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.
\nIMO something like this would be great to have:
\n#[get(\"/\")]\nasync fn index(client: Client) -> Result<String, Error> {\n ...\n}
then the framework is responsible for managing the http client and tests could just exchange the client with a mock.
\nIs there something like this?
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes: managed state.
","upvoteCount":2,"url":"https://github.com/rwf2/Rocket/discussions/2855#discussioncomment-10459491"}}}-
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.
-
Yes: managed state. |
Beta Was this translation helpful? Give feedback.
Yes: managed state.