pub struct Response(_);
http
only.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: DeserializeOwned>(&self) -> Result<T, Error>
Available on crate feature json
only.
pub async fn json<T: DeserializeOwned>(&self) -> Result<T, Error>
json
only.Reads the response to completion, parsing it as JSON.