Skip to main content

Module http

Module http 

Source
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§

pub use request::Request;
pub use response::Response;

Modules§

request
response

Structs§

HeaderName
HeaderValue
Represents an HTTP header field value.
Incoming
A stream of Bytes, used when receiving bodies from the network.
Method
The Request Method (VERB)
Outgoing
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Uri
The URI component of a request.
Version
Represents a version of the HTTP spec.

Enums§

Error

Type Aliases§

Result