16 unstable releases (4 breaking)

0.5.9 Oct 28, 2024
0.5.6 Aug 13, 2024
0.5.5 Jun 13, 2024
0.5.1 Mar 27, 2024
0.2.0 Nov 22, 2023

#455 in Network programming

Download history 59/week @ 2024-07-18 160/week @ 2024-07-25 71/week @ 2024-08-01 187/week @ 2024-08-08 153/week @ 2024-08-15 48/week @ 2024-08-22 154/week @ 2024-08-29 75/week @ 2024-09-05 192/week @ 2024-09-12 522/week @ 2024-09-19 114/week @ 2024-09-26 56/week @ 2024-10-03 74/week @ 2024-10-10 64/week @ 2024-10-17 198/week @ 2024-10-24 92/week @ 2024-10-31

437 downloads per month
Used in 3 crates

MIT license

52KB
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

~2–17MB
~241K SLoC