[][src]Function seed::browser::fetch::fetch

pub async fn fetch<'a>(request: impl Into<Request<'a>>) -> Result<Response>

The main Fetch API function. It fires a HTTP request.

Examples

Simple GET request:

let response = fetch("https://seed-rs.org").await?;
let body = response.text().await?;

POST request with JSON body:

let form = Form{email: "foo@example.com"};
let response = fetch(Request::new("/api").method(Method::Post).json(form)).await?;
let data: SubmitResponse = response.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.