open-library-api-rs 0.1.0

Async Rust client for the Open Library API
Documentation
// v0.0.1
use crate::client::OpenLibraryClient;
use crate::error::{Error, Result};
use crate::models::query::HistoryEntry;

impl OpenLibraryClient {
    /// Fetch the revision history for any Open Library resource.
    ///
    /// `key` is an absolute path like `/works/OL45804W` or `/books/OL7353617M`.
    pub async fn get_resource_history(&self, key: &str) -> Result<Vec<HistoryEntry>> {
        if key.is_empty() {
            return Err(Error::InvalidInput("resource key must not be empty".into()));
        }
        // Strip leading slash so url::Url::join treats it as a relative path.
        let stripped = key.trim_start_matches('/');
        let mut url = self.base_url.join(&format!("{stripped}.json"))?;
        url.query_pairs_mut().append_pair("m", "history");
        self.get_json(url).await
    }
}