How can I perform parallel asynchronous HTTP GET requests with reqwest?

Concurrent requests As of reqwest 0.11.14: use futures::{stream, StreamExt}; // 0.3.27 use reqwest::Client; // 0.11.14 use tokio; // 1.26.0, features = [“macros”] const CONCURRENT_REQUESTS: usize = 2; #[tokio::main] async fn main() { let client = Client::new(); let urls = vec![“https://api.ipify.org”; 2]; let bodies = stream::iter(urls) .map(|url| { let client = &client; async move { let …

Read more

How to test async functions that use Tokio?

Just replace #[test] with #[tokio::test] before any test function. If you use actix-web you can add actix_rt into Cargo.toml and #[actix_rt::test] before the test function #[tokio::test] async fn test_something_async() { let DB = setup().await; // <- the DB is impl std::future::Future type // the DB variable will be used to run another // async function …

Read more