13 个版本 (4 个重大更新)
新版本 0.5.6 | 2024 年 8 月 13 日 |
---|---|
0.5.5 | 2024 年 6 月 13 日 |
0.5.4 | 2024 年 5 月 22 日 |
0.5.1 | 2024 年 3 月 27 日 |
0.2.0 | 2023 年 11 月 22 日 |
#283 in 网络编程
每月 325 次下载
在 3 个 crate 中使用
52KB
1K SLoC
ATrium XRPC 客户端
该库提供实现了在 XrpcClient
中定义的客户端,该客户端位于 atrium-xrpc
。为了适应广泛的用例,提供了四个功能标志,允许开发人员为他们的项目选择最佳的异步 HTTP 客户端库作为后端。
特性
reqwest-default-tls
(默认)reqwest
isahc
以下提供了使用示例。
reqwest
如果您使用 tokio
作为异步运行时,您可能会发现使用具有此特性的 reqwest
后端很方便,这是一个高级异步 HTTP 客户端。默认情况下,使用 reqwest
的 default-tls
功能使用传输层安全性 (TLS)。
[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(())
}
如果您想使用 rustls
TLS 后端,或使用带您自己的配置的 reqwest::*
,您可以直接使用 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(())
}
有关更多详细信息,请参阅 reqwest
文档。
isahc
reqwest
客户端可能无法在除了 tokio
之外的异步运行时上工作。作为替代方案,我们提供了一个使用 isahc
作为后端的功能。
[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(())
}
同样,您可以直接使用您自己的设置指定 isahc::HttpClient
[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(())
}
有关更多详细信息,请参阅 isahc
文档。
WASM 支持
当目标架构为 wasm32 时,只有 reqwest::*
将被启用,并且其客户端实现将自动切换到 WASM 版本。
依赖项
~2–16MB
~230K SLoC