Struct gloo_net::http::Request

source ·
pub struct Request { /* private fields */ }
Available on crate feature http only.
Expand description

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

Implementations§

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

Set the body for this request.

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

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

Replace all the headers.

Sets a header.

Append query parameters to the url, given as (name, value) tuples. Values can be of any type that implements ToString.

It is possible to append the same parameters with the same name multiple times, so .query([("a", "1"), ("a", "2")]) results in the query string a=1&a=2.

Examples

The query parameters can be passed in various different forms:

use std::collections::HashMap;
use gloo_net::http::Request;

let slice_params = [("key", "value")];
let vec_params = vec![("a", "3"), ("b", "4")];
let mut map_params: HashMap<&'static str, &'static str> = HashMap::new();
map_params.insert("key", "another_value");

let r = Request::get("/search")
    .query(slice_params)
    .query(vec_params)
    .query(map_params);
// Result URL: /search?key=value&a=3&b=4&key=another_value

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

A convenience method to set JSON as request body

Note

This method also sets the Content-Type header to application/json

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

The mode you want to use for the request.

Sets the observer callback.

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.

The referrer of the request.

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

Specifies the referrer policy to use for the request.

Sets the request abort signal.

Executes the request.

Creates a new GET Request with url.

Creates a new POST Request with url.

Creates a new PUT Request with url.

Creates a new DELETE Request with url.

Creates a new PATCH Request with url.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.