Skip to main content

HttpEffect

Struct HttpEffect 

Source
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

Source

pub fn new(client: &Client, method: Method, url: impl Into<String>) -> Self

A request with method to url.

Source

pub fn get(client: &Client, url: impl Into<String>) -> Self

A GET request.

Source

pub fn post(client: &Client, url: impl Into<String>) -> Self

A POST request.

Source

pub fn put(client: &Client, url: impl Into<String>) -> Self

A PUT request.

Source

pub fn patch(client: &Client, url: impl Into<String>) -> Self

A PATCH request.

Source

pub fn delete(client: &Client, url: impl Into<String>) -> Self

A DELETE request.

Source

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.

Source

pub fn json<T: Serialize + ?Sized>(self, body: &T) -> Self

Sends body as JSON.

Source

pub fn body(self, body: impl Into<Vec<u8>>) -> Self

Sends body as is.

Source

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.

Source

pub fn idempotency_key_header(self) -> Self

Sends the idempotency key as Idempotency-Key.

Source

pub fn timeout(self, timeout: Duration) -> Self

Gives up on one request after timeout: an ambiguous failure, since it may have been sent.

Source

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.

Source

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).

Source

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 = ().

Source

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.

Source

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, ..).

Trait Implementations§

Source§

impl Clone for HttpEffect

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more