| Crates.io | name-crates-io-client |
| lib.rs | name-crates-io-client |
| version | 0.1.1 |
| created_at | 2025-12-08 05:03:06.681465+00 |
| updated_at | 2025-12-08 06:05:35.698894+00 |
| description | Async crates.io client used by the name generator |
| homepage | https://github.com/factordynamics/name |
| repository | https://github.com/factordynamics/name |
| max_upload_size | |
| id | 1972742 |
| size | 70,714 |
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.
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(())
}
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.