Skip to main content

Crate open_library_api_rs

Crate open_library_api_rs 

Source
Expand description

§open-library-api-rs

Async Rust client for the Open Library API.

Covers every documented public read endpoint: works, editions, books (bibkey), authors, full-text search (5 variants), subjects, covers, user lists, reading logs, the partner/volumes API, recent changes, and generic query/history.

§Features

  • Complete coverage — all 12 Open Library API domains, 30+ methods
  • Strongly typed — dedicated response structs; #[serde(default)] so new API fields never break deserialization
  • Built-in rate limiting — token-bucket via governor; 1 req/s default, 3 req/s with an identifying User-Agent
  • Input validation — OLIDs, ISBN-10/13, slugs, usernames, bibkeys, dates all validated before any HTTP call
  • Securerustls TLS, 10 MB body cap, #![forbid(unsafe_code)]
  • Blocking API — sync wrappers behind the blocking feature flag

§Quick start

use open_library_api_rs::{OpenLibraryClient, Result};
use open_library_api_rs::models::search::SearchParams;

#[tokio::main]
async fn main() -> Result<()> {
    // 1 req/s, rustls TLS, 10 s connect / 30 s request timeout
    let client = OpenLibraryClient::builder().build()?;

    // Fetch a work by its Open Library Work ID
    let work = client.get_work("OL45804W").await?;
    println!("Title: {:?}", work.title);
    println!("Subjects: {:?}", work.subjects);

    // Search across all works
    let results = client.search(SearchParams {
        q: Some("rust programming".into()),
        limit: Some(5),
        ..Default::default()
    }).await?;
    println!("Found {} results", results.num_found);
    for doc in &results.docs {
        println!("  {:?}", doc.title);
    }

    Ok(())
}

§Client configuration

use open_library_api_rs::{OpenLibraryClient, Result};

let client = OpenLibraryClient::builder()
    // Supply a contact email to unlock the 3 req/s identified tier
    .contact_email("me@example.com")?
    .rate_limit(3)
    .build()?;

OpenLibraryClient is Clone + Send + Sync — clone it cheaply to share across tasks or threads.

See client::OpenLibraryClientBuilder for the full set of builder options.

§Cargo features

FeatureDefaultDescription
rustls-tlsonTLS via rustls (no system certs needed)
native-tlsoffTLS via the OS / OpenSSL
blockingoffSync wrappers for every async method

Re-exports§

pub use client::OpenLibraryClient;
pub use error::Error;
pub use error::Result;

Modules§

api
client
error
models
validation