glitr/lustre
This module helps to make the bridge between glitr Routes and lustre
Types
pub opaque type RequestFactory
A RouteRequest contains the data required to send a request to a backend
This data contains a route, all the data from the factory that created the request
as well as path, query and body data that will have to be provided
pub opaque type RouteRequest(p, q, b, c)
Functions
pub fn create_factory() -> RequestFactory
Create a new default factory
By default, it points to “http://localhost:80”
pub fn for_route(
factory: RequestFactory,
route: Route(a, b, c, d),
) -> RouteRequest(a, b, c, d)
Create a RouteRequest given a RequestFactory and a Route
pub fn send(
rreq: RouteRequest(a, b, c, d),
as_msg: fn(Result(d, HttpError)) -> e,
on_error: fn(String) -> Effect(e),
) -> Effect(e)
Send a RouteRequest and handle the result
Uses lustre_http under the hood to send the result, catch the response and transform the data
pub fn with_body(
request: RouteRequest(a, b, c, d),
body: c,
) -> RouteRequest(a, b, c, d)
Set the body data for this request
pub fn with_host(
factory: RequestFactory,
host: String,
) -> RequestFactory
Changes the host of a RequestFactory
pub fn with_options(
request: RouteRequest(a, b, c, d),
options: RouteOptions(a, b, c),
) -> RouteRequest(a, b, c, d)
Set the path, query and body data all at the same time
pub fn with_path(
request: RouteRequest(a, b, c, d),
path: a,
) -> RouteRequest(a, b, c, d)
Set the path data for this request
Note that, for now, you have to call this method before sending the request
pub fn with_port(
factory: RequestFactory,
port: Int,
) -> RequestFactory
Changes the port of a RequestFactory
pub fn with_query(
request: RouteRequest(a, b, c, d),
query: b,
) -> RouteRequest(a, b, c, d)
Set the query data for this request
pub fn with_scheme(
factory: RequestFactory,
scheme: Scheme,
) -> RequestFactory
Changes the scheme of a RequestFactory
Also sets the port to the default for the selected scheme (80 for http and 443 for https)