Body mixin Null safety

The mixin of the Fetch API represents the body of the response/request, allowing you to declare what its content type is and how it should be handled.

is implemented by both Request and Response. This provides these objects with an associated body (a stream), a used flag (initially unset), and a MIME type (initially the empty byte sequence).

Mixin Applications
Annotations

Properties

body ReadableStream?
A simple getter used to expose a ReadableStream of the body contents.
read-only
bodyUsed bool
A Boolean that indicates whether the body has been read.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

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 });
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. [...]
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.
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. [...]
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 [...]
toString() String
A string representation of this object. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

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