Inject an HTTP Client #2855
-
Hi, my http get endpoint itself need the ability to make http requests to other resources and therefore needs an http client. #[get("/")]
async fn index() -> Result<String, Error> {
let client = reqwest::Client::new();
...
} But I don't know if this is good idea and from a testing point of view it is also not ideal because the client should be easy to mock. IMO something like this would be great to have: #[get("/")]
async fn index(client: Client) -> Result<String, Error> {
...
} then the framework is responsible for managing the http client and tests could just exchange the client with a mock. Is there something like this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes: managed state. |
Beta Was this translation helpful? Give feedback.
Yes: managed state.