pub struct RequestBuilder { /* private fields */ }http only.Expand description
A wrapper round web_sys::Request: an http request to be used with the fetch API.
Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn new(url: &str) -> Self
pub fn new(url: &str) -> Self
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>.
Sourcepub fn body(self, body: impl Into<JsValue>) -> Result<Request, Error>
pub fn body(self, body: impl Into<JsValue>) -> Result<Request, Error>
Set the body for this request.
Sourcepub fn cache(self, cache: RequestCache) -> Self
pub fn cache(self, cache: RequestCache) -> Self
A string indicating how the request will interact with the browser’s HTTP cache.
Sourcepub fn credentials(self, credentials: RequestCredentials) -> Self
pub fn credentials(self, credentials: RequestCredentials) -> Self
Controls what browsers do with credentials (cookies, HTTP authentication entries, and TLS client certificates).
Sourcepub fn query<'a, T, V>(self, params: T) -> Self
pub fn query<'a, T, V>(self, params: T) -> Self
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_valueSourcepub fn integrity(self, integrity: &str) -> Self
pub fn integrity(self, integrity: &str) -> Self
The subresource integrity value of the request (e.g.,
sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=).
Sourcepub fn json<T: Serialize + ?Sized>(self, value: &T) -> Result<Request, Error>
Available on crate feature json only.
pub fn json<T: Serialize + ?Sized>(self, value: &T) -> Result<Request, Error>
json only.A convenience method to set JSON as request body
§Note
This method also sets the Content-Type header to application/json
Sourcepub fn mode(self, mode: RequestMode) -> Self
pub fn mode(self, mode: RequestMode) -> Self
The mode you want to use for the request.
Sourcepub fn observe(self, observe: &ObserverCallback) -> Self
pub fn observe(self, observe: &ObserverCallback) -> Self
Sets the observer callback.
Sourcepub fn redirect(self, redirect: RequestRedirect) -> Self
pub fn redirect(self, redirect: RequestRedirect) -> Self
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.
Sourcepub fn referrer(self, referrer: &str) -> Self
pub fn referrer(self, referrer: &str) -> Self
The referrer of the request.
This can be a same-origin URL, about:client, or an empty string.
Sourcepub fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self
pub fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self
Specifies the referrer policy to use for the request.
Sourcepub fn abort_signal(self, signal: Option<&AbortSignal>) -> Self
pub fn abort_signal(self, signal: Option<&AbortSignal>) -> Self
Sets the request abort signal.