9 releases (4 breaking)

new 0.5.2 Apr 17, 2024
0.5.1 Mar 27, 2024
0.4.0 Feb 29, 2024
0.3.0 Feb 20, 2024
0.1.2 Nov 12, 2023

#935 in Network programming

Download history 546/week @ 2023-12-22 7/week @ 2023-12-29 16/week @ 2024-01-05 8/week @ 2024-01-12 26/week @ 2024-02-02 14/week @ 2024-02-09 154/week @ 2024-02-16 187/week @ 2024-02-23 207/week @ 2024-03-01 78/week @ 2024-03-08 58/week @ 2024-03-15 180/week @ 2024-03-22 122/week @ 2024-03-29 53/week @ 2024-04-05

423 downloads per month
Used in 2 crates

MIT license

50KB
1K SLoC

ATrium XRPC Client

Rust

This library provides clients that implement the XrpcClient defined in atrium-xrpc. To accommodate a wide range of use cases, four feature flags are provided to allow developers to choose the best asynchronous HTTP client library for their project as a backend.

Features

  • reqwest-default-tls (default)
  • reqwest
  • isahc

Usage examples are provided below.

reqwest

If you are using tokio as your asynchronous runtime, you may find it convenient to utilize the reqwest backend with this feature, which is a high-level asynchronous HTTP Client. By default, transport layer security (TLS) with reqwest's default-tls feature is used.

[dependencies]
atrium-xrpc-client = "*"
use atrium_xrpc_client::reqwest::ReqwestClient;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ReqwestClient::new("https://bsky.social");
    Ok(())
}

If you want to use the rustls TLS backend, or use reqwest::Client with your own configuration, you can directly specify with the ReqwestClientBuilder:

[dependencies]
atrium-xrpc-client = { version = "*", default-features = false, features = ["reqwest"] }
reqwest = { version = "0.11.24", default-features = false, features = ["rustls-tls"] }
use atrium_xrpc_client::reqwest::ReqwestClientBuilder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ReqwestClientBuilder::new("https://bsky.social")
        .client(
            reqwest::ClientBuilder::new()
                .timeout(std::time::Duration::from_millis(1000))
                .use_rustls_tls()
                .build()?,
        )
        .build();
    Ok(())
}

For more details, refer to the reqwest documentation.

isahc

The reqwest client may not work on asynchronous runtimes other than tokio. As an alternative, we offer the feature that uses isahc as the backend.

[dependencies]
atrium-xrpc-client = { version = "*", default-features = false, features = ["isahc"]}
use atrium_xrpc_client::isahc::IsahcClient;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = IsahcClient::new("https://bsky.social");
    Ok(())
}

Similarly, you can directly specify an isahc::HttpClient with your own settings:

[dependencies]
atrium-xrpc-client = { version = "*", default-features = false, features = ["isahc"]}
isahc = "1.7.2"
use atrium_xrpc_client::isahc::IsahcClientBuilder;
use isahc::config::Configurable;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = IsahcClientBuilder::new("https://bsky.social")
        .client(
            isahc::HttpClientBuilder::new()
                .timeout(std::time::Duration::from_millis(1000))
                .build()?,
        )
        .build();
    Ok(())
}

For more details, refer to the isahc documentation.

WASM support

When the target_arch is wasm32, only reqwest::* will be enabled, and its client implementation automatically switches to the WASM one .

Dependencies

~1–19MB
~249K SLoC