Crate areq_tokio

Crate areq_tokio 

Source
Expand description

areq-tokio

Async HTTP requests for the tokio runtime

This crate is a part of areq library, the runtime-agnostic HTTP requests

§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> {
    // uri contains the server address and path to the http resource
    let uri = Uri::from_static("http://127.0.0.1:3001/hello");

    // establish connection to address "127.0.0.1:3001"
    let (mut client, conn) = Http1::default().connect(&uri).await?;

    // tokio will handle the connection in the background
    // it will automatically terminate when client is dropped
    tokio::spawn(conn);

    // perform GET request to the specified path "/hello"
    client.get(uri, ()).await?.text().await
}

Modules§

body
Body types and traits.
bytes
Provides abstractions for working with bytes.
http
A general purpose library of common HTTP types
http1
The http/1.1 client.
http2
The http/2 client.
negotiate
prelude
The crate’s prelude.
tls
The http client over TLS.
tokio
Tokio related types and traits.

Structs§

Address
The network address.
Request
Response
Session
The communication session between a client and a host.

Enums§

Alt
Error
The handshake error type.
InvalidUri

Traits§

Client
ClientExt
Handshake
The trait to establish a client session over an asynchronous connection.
HandshakeWith
IntoHost