Struct gloo_net::http::Response

source ·
pub struct Response(_);
Available on crate feature http only.
Expand description

The [Request]’s response

Implementations§

source§

impl Response

source

pub fn builder() -> ResponseBuilder

Returns an instance of response builder

source

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.
source

pub fn url(&self) -> String

The URL of the response.

The returned value will be the final URL obtained after any redirects.

source

pub fn redirected(&self) -> bool

Whether or not this response is the result of a request you made which was redirected.

source

pub fn status(&self) -> u16

the HTTP status code of the response.

source

pub fn ok(&self) -> bool

Whether the HTTP status code was a success code (in the range 200 - 299).

source

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.

source

pub fn headers(&self) -> Headers

Gets the headers.

source

pub fn body_used(&self) -> bool

Has the response body been consumed?

If true, then any future attempts to consume the body will error.

source

pub fn body(&self) -> Option<ReadableStream>

Gets the body.

source

pub async fn form_data(&self) -> Result<FormData, Error>

Reads the response to completion, returning it as FormData.

source

pub async fn json<T: DeserializeOwned>(&self) -> Result<T, Error>

Available on crate feature json only.

Reads the response to completion, parsing it as JSON.

source

pub async fn text(&self) -> Result<String, Error>

Reads the response as a String.

source

pub async fn binary(&self) -> Result<Vec<u8>, Error>

Gets the binary response

This works by obtaining the response as an ArrayBuffer, creating a Uint8Array from it and then converting it to Vec<u8>

Trait Implementations§

source§

impl Debug for Response

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Response> for Response

source§

fn from(raw: Response) -> Self

Converts to this type from the input type.
source§

impl From<Response> for Response

source§

fn from(res: Response) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.