I'm building a web server with Actix-web and one of the methods uses reqwest to make HTTP requests to an external API:
#[get("/foo")]
async fn foo() -> impl Responder {
let resp = reqwest::get("https://externalapi.com/bar").await?;
...
}
To improve the performance, I want to reuse the reqwest Client
because it holds a connection pool according to the docs.
However, I cannot use Arc
to share the client because the docs also has the following statement:
You do not have to wrap the Client in an Rc or Arc to reuse it, because it already uses an Arc internally.
How can I share the client across the function calls? Or should I use a different library to create HTTP request inside web servers?