Getting Started
To create an HTTP client, you need to choose a protocol version it'll support. For example, let's use HTTP/1.1. Add the dependency and the required features to a project:
cargo add areq-tokio -F http1
Now you can connect to a remote server, establish an HTTP connection and perform a request:
use {
areq_tokio::{http::Uri, http1::Http1, prelude::*},
std::io::Error,
};
async fn get() -> Result<String, Error> {
let uri = Uri::from_static("http://127.0.0.1:3001/hello");
let (mut client, conn) = Http1::default().connect(&uri).await?;
tokio::spawn(conn);
client.get(uri, ()).await?.text().await
}