Struct Request

Source
pub struct Request { /* private fields */ }
Expand description

A wrapper round web_sys::Request: an http request to be used with the fetch API.

Implementations§

Source§

impl Request

Source

pub fn new(url: &str) -> Request

Creates a new request that will be sent to url.

Uses GET by default. url can be a String, a &str, or a Cow<'a, str>.

Source

pub fn body(self, body: impl Into<JsValue>) -> Request

Set the body for this request.

Source

pub fn cache(self, cache: RequestCache) -> Request

A string indicating how the request will interact with the browser’s HTTP cache.

Source

pub fn credentials(self, credentials: RequestCredentials) -> Request

Controls what browsers do with credentials (cookies, HTTP authentication entries, and TLS client certificates).

Source

pub fn headers(self, headers: Headers) -> Request

Replace all the headers.

Source

pub fn header(self, key: &str, value: &str) -> Request

Sets a header.

Source

pub fn integrity(self, integrity: &str) -> Request

The subresource integrity value of the request (e.g., sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=).

Source

pub fn method(self, method: Method) -> Request

The request method, e.g., GET, POST.

Note that the Origin header is not set on Fetch requests with a method of HEAD or GET.

Source

pub fn mode(self, mode: RequestMode) -> Request

The mode you want to use for the request.

Source

pub fn observe(self, observe: &ObserverCallback) -> Request

Sets the observer callback.

Source

pub fn redirect(self, redirect: RequestRedirect) -> Request

How to handle a redirect response:

  • follow: Automatically follow redirects. Unless otherwise stated the redirect mode is set to follow
  • error: Abort with an error if a redirect occurs.
  • manual: Caller intends to process the response in another context. See WHATWG fetch standard for more information.
Source

pub fn referrer(self, referrer: &str) -> Request

The referrer of the request.

This can be a same-origin URL, about:client, or an empty string.

Source

pub fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Request

Specifies the referrer policy to use for the request.

Source

pub fn abort_signal(self, signal: Option<&AbortSignal>) -> Request

Sets the request abort signal.

Source

pub async fn send(self) -> Result<Response, Error>

Executes the request.

Source

pub fn get(url: &str) -> Request

Creates a new GET Request with url.

Source

pub fn post(url: &str) -> Request

Creates a new POST Request with url.

Source

pub fn put(url: &str) -> Request

Creates a new PUT Request with url.

Source

pub fn delete(url: &str) -> Request

Creates a new DELETE Request with url.

Source

pub fn patch(url: &str) -> Request

Creates a new PATCH Request with url.

Trait Implementations§

Source§

impl Debug for Request

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.