Skip to main content

Crate effectful_reqwest

Crate effectful_reqwest 

Source
Expand description

reqwest integration for the workspace effect crate.

§Model

§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 Client to make Requests with.
ClientBuilder
A ClientBuilder can be used to create a Client with custom configuration.
Error
The Errors that may occur when processing a Request.
PooledClient
Wraps Client in an Arc so it can live in Pool (PartialEq uses pointer identity).
RequestBuilder
A builder to construct the properties of a Request.
ReqwestClientKey
Tag for the default reqwest::Client service in the environment R. Nominal service key (service_key!). Implements Equal and EffectHash through the standard derives—Brand-style structural equality for this ZST tag.
ReqwestPoolKey
Tag for Pool<PooledClient, Never> in R. Nominal service key (service_key!). Implements Equal and EffectHash through the standard derives—Brand-style structural equality for this ZST tag.
Response
A Response to a submitted Request.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).

Enums§

JsonSchemaError
Failure from json_schema.

Traits§

NeedsReqwestClient
Supertrait for environments that expose a reqwest::Client at ReqwestClientKey.
NeedsReqwestPool
Supertrait for environments that expose a Pool of PooledClient at ReqwestPoolKey.

Functions§

bytes
send then Response::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
send then Response::json.
json_schema
send then decode the response body as JSON through schema (Schema::decode_unknown).
layer_reqwest_client
effectful::Layer that provides a cloneable reqwest::Client.
layer_reqwest_client_default
Same as layer_reqwest_client, using reqwest::Client::new.
layer_reqwest_client_with
Build a client from reqwest::ClientBuilder and expose it as a layer.
layer_reqwest_pool
Layer that installs a Pool::make_with_ttl of PooledClient (factory: fresh Client::new per 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::send using the client from R.
send_pooled
send with a client checked out from ReqwestPoolKey; returns to the pool when the inner scope closes.
text
send then Response::text.

Type Aliases§

ReqwestClientService
[effectful::Service] cell holding a reqwest::Client.
ReqwestPoolService
[effectful::Service] cell holding a Pool of PooledClient.