Response class Null safety

The interface of the Fetch API represents the response to a request.

You can create a new object using the Response.Response() constructor, but you are more likely to encounter a object being returned as the result of another API operation—for example, a service worker Fetchevent.respondWith, or a simple WindowOrWorkerGlobalScope.fetch().

Mixed in types
Annotations

Constructors

Response([dynamic body, ResponseInit? init])
factory

Properties

body ReadableStream?
A simple getter used to expose a ReadableStream of the body contents.
read-only, inherited
bodyUsed bool
A Boolean that indicates whether the body has been read.
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
headers Headers
The Headers object associated with the response.
read-only
ok bool
A boolean indicating whether the response was successful (status in the range 200299) or not.
read-only
redirected bool
Indicates whether or not the response is the result of a redirect (that is, its URL list has more than one entry).
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
status int
The status code of the response. (This will be 200 for a success).
read-only
statusText String
The status message corresponding to the status code. (e.g., OK for 200).
read-only
type ResponseType
The type of the response (e.g., basic, cors).
read-only
url String
The URL of the response.
read-only

Methods

arrayBuffer() Promise<ByteBuffer>
Takes a Response stream and reads it to completion. It returns a promise that resolves with an ArrayBuffer. response.arrayBuffer().then(function(buffer) { // do something with buffer });
inherited
blob() Promise<Blob>
Takes a Response stream and reads it to completion. It returns a promise that resolves with a Blob. response.blob().then(function(myBlob) { // do something with myBlob }); In our fetch request example (run fetch request live), we create a new request using the Request() constructor, then use it to fetch a JPG. When the fetch is successful, we read a Blob out of the response using blob(), put it into an object URL using URL.createObjectURL, and then set that URL as the source of an element to display the image. [...]
inherited
clone() Response
Creates a clone of a Response object. var response2 = response1.clone(); In our Fetch Response clone example (see Fetch Response clone live) we create a new Request object using the Request() constructor, passing it a JPG path. We then fetch this request using fetch(). When the fetch resolves successfully, we clone it, extract a blob from both responses using two Body.blob calls, create object URLs out of the blobs using URL.createObjectURL, and display them in two separate elements. [...]
formData() Promise<FormData>
Takes a Response stream and reads it to completion. It returns a promise that resolves with a FormData object. response.formData() .then(function(formdata) { // do something with your formdata }); TBD.
inherited
json() Promise
Takes a Response stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON. response.json().then(data => { // do something with your data }); In our fetch json example (run fetch json live), we create a new request using the Request() constructor, then use it to fetch a .json file. When the fetch is successful, we read and parse the data using json(), then read values out of the resulting objects as you'd expect and insert them into list items to display our product data. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
text() Promise<String>
Takes a Response stream and reads it to completion. It returns a promise that resolves with a USVString (text). The response is always decoded using UTF-8. response.text().then(function (text) { // do something with the text response }); In our fetch text example (run fetch text live), we have an [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited

Static Methods

error() Response
Returns a new Response object associated with a network error. var errorResponse = Response.error(); TBD (does not yet appear to be supported anywhere).
redirect(String url, [int? status = 302]) Response
Creates a new response with a different URL. var response = Response.redirect(url, status); responseObj.redirect('https://www.example.com', 302);