Expand description
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 request = Request::new("/api").method(Method::Post).json(form).expect("Error in parsing Request");
let response = fetch(request).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.