Expand description
reqwest integration for the workspace effect crate.
§Model
- Treat
reqwest::Clientas a service keyed byReqwestClientKey(Effect.ts-style tag). - Build it at the composition root with
layer_reqwest_clientorlayer_reqwest_client_with. - Express HTTP calls as
Effectvalues usingsend,text,bytes, orjson. - Optional:
layer_reqwest_pool+send_pooledto keep aPoolofPooledClientwith TTL. - Optional:
json_schemadecodes JSON bodies viaSchema::decode_unknownsoeffectful::schema::ParseErrorcarries field paths.
§Relation to effectful_tokio
This crate depends only on effect (and reqwest). Async HTTP steps are ordinary
Effect::new_async bodies; drive them on Tokio with
effectful::run_async or the same symbol re-exported from effectful_tokio as
effectful_tokio::run_async (recommended in Tokio services so sleep/yield stay consistent).
§Example
ⓘ
use effectful::{ctx, run_async, service, Context, Cons, Nil};
use effectful_reqwest::{ReqwestClientKey, send};
type Env = Context<Cons<effectful::Service<ReqwestClientKey, reqwest::Client>, Nil>>;
let env = Context::new(Cons(
service::<ReqwestClientKey, _>(reqwest::Client::new()),
Nil,
));
let eff = send(|c| c.get("https://example.com"));
let _res = run_async(eff, env).await?;§Runnable examples
See examples/ (e.g. cargo run -p effectful_reqwest --example 010_wiremock_get_text).
Structs§
- Client
- An asynchronous
Clientto make Requests with. - Client
Builder - A
ClientBuildercan be used to create aClientwith custom configuration. - Error
- The Errors that may occur when processing a
Request. - Pooled
Client - Wraps
Clientin anArcso it can live inPool(PartialEquses pointer identity). - Request
Builder - A builder to construct the properties of a
Request. - Reqwest
Client Key - Tag for the default
reqwest::Clientservice in the environmentR. Nominal service key (service_key!). ImplementsEqualandEffectHashthrough the standard derives—Brand-style structural equality for this ZST tag. - Reqwest
Pool Key - Tag for
Pool<PooledClient,Never>inR. Nominal service key (service_key!). ImplementsEqualandEffectHashthrough the standard derives—Brand-style structural equality for this ZST tag. - Response
- A Response to a submitted
Request. - Status
Code - An HTTP status code (
status-codein RFC 9110 et al.).
Enums§
- Json
Schema Error - Failure from
json_schema.
Traits§
- Needs
Reqwest Client - Supertrait for environments that expose a
reqwest::ClientatReqwestClientKey. - Needs
Reqwest Pool - Supertrait for environments that expose a
PoolofPooledClientatReqwestPoolKey.
Functions§
- bytes
sendthenResponse::bytes.- delete
- Shorthand for
send(|c| c.delete(url)). - get
- Shorthand for
send(|c| c.get(url)). - head
- Shorthand for
send(|c| c.head(url)). - json
sendthenResponse::json.- json_
schema sendthen decode the response body as JSON throughschema(Schema::decode_unknown).- layer_
reqwest_ client effectful::Layerthat provides a cloneablereqwest::Client.- layer_
reqwest_ client_ default - Same as
layer_reqwest_client, usingreqwest::Client::new. - layer_
reqwest_ client_ with - Build a client from
reqwest::ClientBuilderand expose it as a layer. - layer_
reqwest_ pool - Layer that installs a
Pool::make_with_ttlofPooledClient(factory: freshClient::newper slot). - patch
- Shorthand for
send(|c| c.patch(url)). - post
- Shorthand for
send(|c| c.post(url)). - put
- Shorthand for
send(|c| c.put(url)). - send
- Run
RequestBuilder::sendusing the client fromR. - send_
pooled sendwith a client checked out fromReqwestPoolKey; returns to the pool when the inner scope closes.- text
sendthenResponse::text.
Type Aliases§
- Reqwest
Client Service - [
effectful::Service] cell holding areqwest::Client. - Reqwest
Pool Service - [
effectful::Service] cell holding aPoolofPooledClient.