4 releases (2 breaking)
0.3.0 | May 22, 2023 |
---|---|
0.2.0 | May 13, 2023 |
0.1.1 | May 7, 2023 |
0.1.0 | May 3, 2023 |
#61 in HTTP client
160 downloads per month
205KB
5K
SLoC
ATrium API: Rust library for Bluesky's atproto services
ATrium API is a Rust library that includes the definitions of XRPC requests and their associated input/output model types. These codes are generated from the Lexicon schema on atproto.com.
Usage
You can use any HTTP client that implements xrpc::HttpClient
to make use of the XRPC requests. Below is the simplest example using reqwest
.
#[derive(Default)]
struct MyClient(reqwest::Client);
#[async_trait::async_trait]
impl atrium_api::xrpc::HttpClient for MyClient {
async fn send(
&self,
req: http::Request<Vec<u8>>,
) -> Result<http::Response<Vec<u8>>, Box<dyn std::error::Error>> {
let res = self.0.execute(req.try_into()?).await?;
let mut builder = http::Response::builder().status(res.status());
for (k, v) in res.headers() {
builder = builder.header(k, v);
}
builder
.body(res.bytes().await?.to_vec())
.map_err(Into::into)
}
}
#[async_trait::async_trait]
impl atrium_api::xrpc::XrpcClient for MyClient {
fn host(&self) -> &str {
"https://bsky.social"
}
fn auth(&self) -> Option<&str> {
None
}
}
atrium_api::impl_traits!(MyClient);
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use atrium_api::com::atproto::server::create_session::{CreateSession, Input};
let session = MyClient::default()
.create_session(Input {
identifier: "<your handle>.bsky.social".into(),
password: "<your app password>".into(),
})
.await?;
println!("{:?}", session);
Ok(())
}
Dependencies
~1.7–2.6MB
~54K SLoC