pub struct Response(/* private fields */);
Expand description
The [Request
]’s response
Implementations§
Source§impl Response
impl Response
Sourcepub fn builder() -> ResponseBuilder
pub fn builder() -> ResponseBuilder
Returns an instance of response builder
Sourcepub fn type_(&self) -> ResponseType
pub fn type_(&self) -> ResponseType
The type read-only property of the Response interface contains the type of the response.
It can be one of the following:
- basic: Normal, same origin response, with all headers exposed except “Set-Cookie” and “Set-Cookie2″.
- cors: Response was received from a valid cross-origin request. Certain headers and the body may be accessed.
- error: Network error. No useful information describing the error is available. The Response’s status is 0, headers are empty and immutable. This is the type for a Response obtained from Response.error().
- opaque: Response for “no-cors” request to cross-origin resource. Severely restricted.
- opaqueredirect: The fetch request was made with redirect: “manual”. The Response’s status is 0, headers are empty, body is null and trailer is empty.
Sourcepub fn url(&self) -> String
pub fn url(&self) -> String
The URL of the response.
The returned value will be the final URL obtained after any redirects.
Sourcepub fn redirected(&self) -> bool
pub fn redirected(&self) -> bool
Whether or not this response is the result of a request you made which was redirected.
Sourcepub fn status(&self) -> u16
pub fn status(&self) -> u16
the HTTP status code of the response.
Sourcepub fn ok(&self) -> bool
pub fn ok(&self) -> bool
Whether the HTTP status code
was a success code (in the range 200 - 299
).
Sourcepub fn status_text(&self) -> String
pub fn status_text(&self) -> String
The status message corresponding to the
HTTP status code from
Response::status
.
For example, this would be ‘OK’ for a status code 200, ‘Continue’ for 100, or ‘Not Found’ for 404.
Sourcepub fn body_used(&self) -> bool
pub fn body_used(&self) -> bool
Has the response body been consumed?
If true, then any future attempts to consume the body will error.
Sourcepub fn body(&self) -> Option<ReadableStream>
pub fn body(&self) -> Option<ReadableStream>
Gets the body.
Sourcepub async fn form_data(&self) -> Result<FormData, Error>
pub async fn form_data(&self) -> Result<FormData, Error>
Reads the response to completion, returning it as FormData
.
Sourcepub async fn json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn json<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Reads the response to completion, parsing it as JSON.