pub struct HttpEffect { /* private fields */ }Expand description
An HTTP request as an effect’s action. Build it, then turn it into an
action with Self::send_json or Self::send.
Implementations§
Source§impl HttpEffect
impl HttpEffect
Sourcepub fn new(client: &Client, method: Method, url: impl Into<String>) -> Self
pub fn new(client: &Client, method: Method, url: impl Into<String>) -> Self
A request with method to url.
Sourcepub fn header(self, name: &str, value: &str) -> Self
pub fn header(self, name: &str, value: &str) -> Self
Adds a header. Credentials belong here or in the client, not in the effect’s input.
Sourcepub fn idempotency_header(self, name: &str) -> Self
pub fn idempotency_header(self, name: &str) -> Self
Sends the effect’s idempotency key in header name on every attempt.
The key is the same across attempts, so a server that honours it
applies the request once. Pair with
EffectBuilder::remote_idempotency.
Sourcepub fn idempotency_key_header(self) -> Self
pub fn idempotency_key_header(self) -> Self
Sends the idempotency key as Idempotency-Key.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Gives up on one request after timeout: an ambiguous failure, since
it may have been sent.
Sourcepub fn client_follows_no_redirects(self) -> Self
pub fn client_follows_no_redirects(self) -> Self
Declares that the client does not follow redirects: it was built
with .redirect(reqwest::redirect::Policy::none()). Only then does a
connection failure prove the request was never sent, so that it is
retried as Transient, even for an irreversible write. Without it,
a connection failure is ambiguous. This does not change the client:
declaring it for a client that does follow redirects can duplicate
effects.
Sourcepub fn classify_status(
self,
classify: impl Fn(StatusCode, &HeaderMap) -> Option<StatusClass> + Send + Sync + 'static,
) -> Self
pub fn classify_status( self, classify: impl Fn(StatusCode, &HeaderMap) -> Option<StatusClass> + Send + Sync + 'static, ) -> Self
Overrides how statuses are classified: return Some to decide,
None to fall back to classify_status. For APIs with their own
conventions, e.g. a 409 that means “already done”. A failure after
a followed redirect is still ambiguous (see the crate docs).
Sourcepub fn send_json<T: DeserializeOwned + Send + 'static>(
self,
) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<T, EffectFailure>> + Send>> + Send + Sync + 'static
pub fn send_json<T: DeserializeOwned + Send + 'static>( self, ) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<T, EffectFailure>> + Send>> + Send + Sync + 'static
The action: sends the request and parses a successful response as
JSON T. An empty body reads as JSON null, e.g. for T = ().
Sourcepub fn send(
self,
) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<HttpResponse, EffectFailure>> + Send>> + Send + Sync + 'static
pub fn send( self, ) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<HttpResponse, EffectFailure>> + Send>> + Send + Sync + 'static
The action: sends the request and returns the successful response’s status and body as text.
Sourcepub fn verify_json<T: DeserializeOwned + Send + 'static>(
self,
) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<Verification<T>, EffectFailure>> + Send>> + Send + Sync + 'static
pub fn verify_json<T: DeserializeOwned + Send + 'static>( self, ) -> impl Fn(EffectContext) -> Pin<Box<dyn Future<Output = Result<Verification<T>, EffectFailure>> + Send>> + Send + Sync + 'static
A verification: a lookup whose 2xx response, parsed as JSON T,
confirms the effect, and whose 404 or 410 (only those) says it did not
apply. Any other status or error is a failed check, which the runtime
treats as inconclusive: a broken lookup must never be read as “not
applied”. Pass it to .verify(..) if the lookup reads its own
writes, else to .verify_eventually(settle, ..).