Trait reqwest_middleware::Middleware [−][src]
pub trait Middleware: 'static + Send + Sync { fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: Request,
extensions: &'life1 mut Extensions,
next: Next<'life2>
) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait; }
Expand description
When attached to a ClientWithMiddleware
(generally using with
), middleware is run
whenever the client issues a request, in the order it was attached.
Example
use reqwest::{Client, Request, Response}; use reqwest_middleware::{ClientBuilder, Middleware, Next, Result}; use truelayer_extensions::Extensions; struct TransparentMiddleware; #[async_trait::async_trait] impl Middleware for TransparentMiddleware { async fn handle( &self, req: Request, extensions: &mut Extensions, next: Next<'_>, ) -> Result<Response> { next.run(req, extensions).await } }
Required methods
Invoked with a request before sending it. If you want to continue processing the request,
you should explicitly call next.run(req, extensions)
.
If you need to forward data down the middleware stack, you can use the extensions
argument.