Expand description
§Crate Checker
Rust crate information retrieval tool that provides both a powerful CLI interface and a library API for querying crates.io.
§Features
- Crate existence checking - Quickly verify if a crate exists
- Version information - Get detailed version history and metadata
- Dependency analysis - Explore dependencies and their relationships
- Download statistics - Access download metrics and trends
- Batch processing - Process multiple crates efficiently
- REST API server - Run as an HTTP server for integration
- Multiple output formats - JSON, YAML, Table, CSV, and compact
- Async/concurrent - Built on Tokio for excellent performance
§Quick Start
Add to your Cargo.toml
:
[dependencies]
crate-checker = "0.1.0"
§Library Usage
§Basic Example
use crate_checker::{CrateClient, Result};
#[tokio::main]
async fn main() -> Result<()> {
// Create a client with default settings
let client = CrateClient::new();
// Check if a crate exists
let exists = client.crate_exists("serde").await?;
println!("Serde exists: {}", exists);
// Get detailed information
let info = client.get_crate_info("tokio").await?;
println!("Tokio version: {}", info.newest_version);
println!("Downloads: {}", info.downloads);
Ok(())
}
§Custom Client Configuration
use crate_checker::{CrateClient, Result};
use std::time::Duration;
let client = CrateClient::builder()
.base_url("https://crates.io/api/v1")
.timeout(Duration::from_secs(30))
.user_agent("my-app/1.0")
.build()?;
§Batch Processing
use crate_checker::{CrateClient, Result};
use std::collections::HashMap;
let client = CrateClient::new();
// Process multiple crates with specific versions
let mut versions = HashMap::new();
versions.insert("serde".to_string(), "0.1.0".to_string());
versions.insert("tokio".to_string(), "latest".to_string());
let result = client.process_crate_version_map(versions).await?;
println!("Processed {} crates", result.total_processed);
println!("Successful: {}, Failed: {}", result.successful, result.failed);
§Error Handling
use crate_checker::{CrateClient, CrateCheckerError, Result};
let client = CrateClient::new();
match client.get_crate_info("unknown-crate").await {
Ok(info) => println!("Found: {}", info.name),
Err(CrateCheckerError::CrateNotFound(name)) => {
println!("Crate '{}' not found", name);
}
Err(e) if e.is_recoverable() => {
println!("Temporary error, can retry: {}", e);
}
Err(e) => {
println!("Error: {}", e.user_message());
}
}
§CLI Usage
The crate-checker binary provides a comprehensive command-line interface:
# Check if a crate exists
crate-checker check serde
# Get detailed information with dependencies
crate-checker info tokio --deps --stats
# Search for crates
crate-checker search "http client" --limit 10
# Check multiple crates
crate-checker check-multiple serde tokio reqwest
# Start API server
crate-checker server --port 8080
§API Server
Run crate-checker as an HTTP server:
crate-checker server --port 8080 --cors
Available endpoints:
GET /health
- Health checkGET /api/crates/{name}
- Get crate infoGET /api/search?q={query}
- Search cratesPOST /api/batch
- Batch processing
§Configuration
Configure via file (crate-checker.toml
) or environment variables:
[server]
port = 8080
host = "0.0.0.0"
[cache]
enabled = true
ttl_seconds = 300
[crates_io]
timeout_seconds = 30
Environment variables: CRATE_CHECKER__SECTION__KEY
§Performance Tips
- Enable caching to reduce API calls
- Use batch operations for multiple crates
- Configure appropriate timeouts
- Use parallel processing when available
§Examples
See the examples/
directory for more usage patterns:
basic_usage.rs
- Simple API usagebatch_processing.rs
- Batch operationsmonitor_updates.rs
- Version monitoringcustom_client.rs
- Advanced configuration
Re-exports§
pub use client::CrateClient;
pub use client::CrateClientBuilder;
pub use error::CrateCheckerError;
pub use error::Result;
pub use types::BatchInput;
pub use types::BatchOperation;
pub use types::BatchRequest;
pub use types::BatchResponse;
pub use types::BatchResult;
pub use types::BatchTarget;
pub use types::CrateCheckResult;
pub use types::CrateInfo;
pub use types::CrateSearchResult;
pub use types::CrateStatus;
pub use types::Dependency;
pub use types::DownloadStats;
pub use types::Owner;
pub use types::Version;
pub use types::VersionDownload;
pub use config::AppConfig;
pub use config::EnvironmentConfig;
Modules§
- cli
- Command-line interface for the crate checker application
- client
- HTTP client for interacting with the crates.io API
- config
- Configuration management for the crate checker application
- error
- Error types for the crate checker application
- server
- HTTP server implementation for the crate checker API
- types
- Data types and structures for the crate checker application
- utils
- Utility functions for the crate checker application
Constants§
- DEFAULT_
API_ URL - Default crates.io API base URL
- DEFAULT_
SERVER_ PORT - Default server port
- DEFAULT_
TIMEOUT_ SECS - Default request timeout in seconds
- DEFAULT_
USER_ AGENT - Default user agent for requests
- NAME
- Library name
- VERSION
- Library version