name-crates-io-client

Crates.ioname-crates-io-client
lib.rsname-crates-io-client
version0.1.1
created_at2025-12-08 05:03:06.681465+00
updated_at2025-12-08 06:05:35.698894+00
descriptionAsync crates.io client used by the name generator
homepagehttps://github.com/factordynamics/name
repositoryhttps://github.com/factordynamics/name
max_upload_size
id1972742
size70,714
refcell (refcell)

documentation

README

Crates.io Client

Async client for querying crates.io from the name generator. It wraps reqwest with small helpers tailored to availability checks and metadata fetches. The base URL is configurable for tests and self-hosted registries.

Usage

use name_crates_io_client::CratesClient;

#[tokio::main]
async fn main() -> eyre::Result<()> {
    let client = CratesClient::new("https://crates.io");

    if client.exists("serde").await? {
        if let Some(info) = client.fetch_metadata("serde").await? {
            println!("serde downloads: {}", info.downloads);
        }
    }

    Ok(())
}

API

  • CratesClient { inner: reqwest::Client, base_url: String } stores the HTTP client and API root.
  • async fn exists(&self, name: &str) -> eyre::Result<bool> returns true on 200 OK, false on 404 Not Found, and errors on other statuses.
  • async fn fetch_metadata(&self, name: &str) -> eyre::Result<Option<CrateInfo>> fetches crate metadata on 200 OK, yields None for 404 Not Found, and errors otherwise.

Responses are deserialized with serde and rely on Rustls-backed TLS to avoid OpenSSL dependencies. The default client sets JSON Accept headers and a workspace-specific user agent; consumers can provide their own reqwest::Client via with_client when needed.

Commit count: 0

cargo fmt