reqwest-chain
Apply custom criteria to any reqwest response, deciding when and how to retry.
reqwest-chain builds on reqwest-middleware, to allow you to focus on your core logic without the boilerplate.
Use case
This crate is a more general framework than reqwest-retry. It allows inspection of:
- The result of the previous request
- The state of the retry chain
- The global state of your middleware
Based on this information, it allows updating any aspect of the next request.
If all you need is a simple retry, you should use reqwest-retry.
Getting started
See the tests directory for several examples.
You should implement Chainer for your middleware struct. This uses the chain
method to make a decision after each request respones:
- If another request is required, update the previous request to form the
next request in the chain, and return
Ok(None). - If the response is ready, return it inside
Ok(Some(response)). - If an error occurs and you cannot continue, return
Err(error).
Below is the initial use case; refresh some authorization credential on request failure.
use ;
use ;
use ;
use ;
// Mimic some external function that returns a valid token.
;
async
Thanks
Many thanks to the prior work in this area, namely:
reqwest-middlewarefor the underlying frameworkreqwest-retryfor inspiration