[−][src]Struct seed::browser::fetch::Request
Its methods configure the request, and handle the response. Many of them return the original struct, and are intended to be used chained together.
Implementations
impl<'a> Request<'a>
[src]
pub fn new(url: impl Into<Cow<'a, str>>) -> Self
[src]
Create new request based on the provided url.
To get a Response
you need to pass
Request
to the fetch
function.
pub fn headers(self, headers: Headers<'a>) -> Self
[src]
Set headers for this request. It will replace any existing headers.
pub fn header(self, header: Header<'a>) -> Self
[src]
Set specific header.
pub const fn method(self, method: Method) -> Self
[src]
Set HTTP method. Default method is GET
.
pub fn body(self, body: JsValue) -> Self
[src]
Set request body to provided JsValue
. Consider using json
or text
methods instead.
Panics
This method will panic when request method is GET or HEAD.
pub fn json<T: Serialize + ?Sized>(self, data: &T) -> Result<Self>
[src]
Set request body by JSON encoding provided data.
It will also set Content-Type
header to application/json; charset=utf-8
.
Errors
This method can fail if JSON serialization fail. It will then
return FetchError::SerdeError
.
pub fn text(self, text: impl AsRef<str>) -> Self
[src]
Set request body to a provided string.
It will also set Content-Type
header to text/plain; charset=utf-8
.
pub const fn mode(self, mode: RequestMode) -> Self
[src]
Set request mode.
pub const fn credentials(self, credentials: RequestCredentials) -> Self
[src]
Set request credentials.
pub const fn cache(self, cache: RequestCache) -> Self
[src]
Set request cache mode.
pub const fn redirect(self, redirect: RequestRedirect) -> Self
[src]
Set request redirect mode.
pub fn referrer(self, referrer: &impl ToString) -> Self
[src]
Set request referrer.
pub const fn referrer_policy(self, referrer_policy: ReferrerPolicy) -> Self
[src]
Set request referrer policy.
pub fn integrity(self, integrity: &impl ToString) -> Self
[src]
Set request subresource integrity.
pub fn timeout(self, timeout: u32) -> Self
[src]
Set request timeout in milliseconds.
pub fn controller(self) -> (Self, RequestController)
[src]
Get the request controller that allows to abort request or disable request's timeout.
Example
let (request, controller) = Request::new("http://example.com").controller();
pub async fn fetch(self) -> Result<Response>
[src]
Fetch request. It's a chainable alternative to fetch(request)
.
Example
orders.perform_cmd({ let message = model.new_message.clone(); async { Msg::Fetched(send_message(message).await) } }); ... async fn send_message(new_message: String) -> fetch::Result<shared::SendMessageResponseBody> { Request::new(get_request_url()) .method(Method::Post) .json(&shared::SendMessageRequestBody { text: new_message })? .fetch() .await? .check_status()? .json() .await }
Errors
fetch
will return Err
only on network errors. This means that
even if you get Ok
from this function, you still need to check
Response
status for HTTP errors.
Trait Implementations
impl<'a> Clone for Request<'a>
[src]
impl<'a> Debug for Request<'a>
[src]
impl<'a> Default for Request<'a>
[src]
impl<'a, T: Into<Cow<'a, str>>> From<T> for Request<'a>
[src]
impl<'a> From<Url> for Request<'a>
[src]
impl<'_> TryFrom<Request<'_>> for Request
[src]
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Request<'a>
impl<'a> !Send for Request<'a>
impl<'a> !Sync for Request<'a>
impl<'a> Unpin for Request<'a>
impl<'a> !UnwindSafe for Request<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,