50 releases (23 breaking)

0.24.2 Aug 14, 2024
0.23.2 Jul 3, 2024
0.20.0 Mar 27, 2024
0.15.0 Dec 23, 2023
0.4.0 Jun 30, 2023

#228 in Web programming

Download history 586/week @ 2024-05-19 190/week @ 2024-05-26 55/week @ 2024-06-02 168/week @ 2024-06-09 238/week @ 2024-06-16 170/week @ 2024-06-23 201/week @ 2024-06-30 84/week @ 2024-07-07 30/week @ 2024-07-14 48/week @ 2024-07-21 536/week @ 2024-07-28 29/week @ 2024-08-04 484/week @ 2024-08-11 63/week @ 2024-08-18 97/week @ 2024-08-25 75/week @ 2024-09-01

722 downloads per month
Used in 5 crates (3 directly)

MIT license

680KB
16K SLoC

ATrium API: Rust library for Bluesky's atproto services

Rust

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

Any HTTP client that implements atrium_xrpc::HttpClient can be used to handle XRPC requests. Since atrium_xrpc_client provides several implementations, it is recommended to use one of them that fits your project requirements.

use atrium_api::client::AtpServiceClient;
use atrium_xrpc_client::reqwest::ReqwestClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AtpServiceClient::new(ReqwestClient::new("https://bsky.social"));
    let result = client
        .service
        .com
        .atproto
        .server
        .create_session(
            atrium_api::com::atproto::server::create_session::InputData {
                auth_factor_token: None,
                identifier: "alice@mail.com".into(),
                password: "hunter2".into(),
            }
            .into(),
        )
        .await;
    println!("{:?}", result);
    Ok(())
}

AtpAgent (agent feature)

While AtpServiceClient can be used for simple XRPC calls, it is better to use AtpAgent, which has practical features such as session management.

use atrium_api::agent::{store::MemorySessionStore, AtpAgent};
use atrium_xrpc_client::reqwest::ReqwestClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let agent = AtpAgent::new(
        ReqwestClient::new("https://bsky.social"),
        MemorySessionStore::default(),
    );
    agent.login("alice@mail.com", "hunter2").await?;
    let result = agent
        .api
        .com
        .atproto
        .server
        .get_session()
        .await?;
    println!("{:?}", result);
    Ok(())
}

Features

The AtpAgent used in the above example is included in the agent feature. atrium-api enables the agent and bluesky features by default. It is possible to opt-out if not needed.

  • agent: enable the agent module.
  • bluesky: enable bluesky-specific lexicon definitions and XRPC methods.
    • It is also possible to enable only the namespace specified by namespace-*.

Dependencies

~7–14MB
~180K SLoC