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?; # GET request inside server
...
}
To improve the performance, I want to reuse the client of reqwest, because it holds a connection pool, according to the doc. However, I cannot use Arc
to share the client, because the doc 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?
Aucun commentaire:
Enregistrer un commentaire