Expand description
HTTP request and response handling for the browser & server environment.
§Browser Example
(Ignore because of dependency cycle)
ⓘ
use rustolio::prelude::*;
use rustolio::utils::http::Request;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
struct Data {
field1: String,
}
fn fetch_component() -> Elements {
let data: Signal<Option<Data>> = Signal::new(None);
spawn(async move {
let res = Request::get("https://api.example.com/data")
.fetch()
.await
.unwrap()
.json::<Data>()
.await
.unwrap()
.into_body();
data.set(Some(res));
});
elements! {
move || {
let Some(data) = data.value() else {
return "Loading...".to_string();
};
data.field1
}
}
}Re-exports§
Modules§
Structs§
- Header
Name - Header
Value - Represents an HTTP header field value.
- Incoming
- A stream of
Bytes, used when receiving bodies from the network. - Method
- The Request Method (VERB)
- Outgoing
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Uri
- The URI component of a request.
- Version
- Represents a version of the HTTP spec.