Struct crates_io_api::AsyncClient
source · pub struct AsyncClient { /* private fields */ }
Expand description
Asynchronous client for the crates.io API.
Implementations§
source§impl Client
impl Client
sourcepub fn new(
user_agent: &str,
rate_limit: Duration
) -> Result<Self, InvalidHeaderValue>
pub fn new( user_agent: &str, rate_limit: Duration ) -> Result<Self, InvalidHeaderValue>
Instantiate a new client.
Returns an Error
if the given user agent is invalid.
To respect the offical Crawler Policy, you must specify both a descriptive user agent and a rate limit interval.
At most one request will be executed in the specified duration. The guidelines suggest 1 per second or less. (Only one request is executed concurrenly, even if the given Duration is 0).
Example user agent: "my_bot (my_bot.com/info)"
or "my_bot (help@my_bot.com)"
.
let client = crates_io_api::AsyncClient::new(
"my_bot (help@my_bot.com)",
std::time::Duration::from_millis(1000),
).unwrap();
sourcepub fn with_http_client(client: HttpClient, rate_limit: Duration) -> Self
pub fn with_http_client(client: HttpClient, rate_limit: Duration) -> Self
Instantiate a new client.
To respect the offical Crawler Policy, you must specify both a descriptive user agent and a rate limit interval.
At most one request will be executed in the specified duration. The guidelines suggest 1 per second or less. (Only one request is executed concurrenly, even if the given Duration is 0).
sourcepub async fn summary(&self) -> Result<Summary, Error>
pub async fn summary(&self) -> Result<Summary, Error>
Retrieve a summary containing crates.io wide information.
sourcepub async fn get_crate(&self, crate_name: &str) -> Result<CrateResponse, Error>
pub async fn get_crate(&self, crate_name: &str) -> Result<CrateResponse, Error>
Retrieve information of a crate.
If you require detailed information, consider using full_crate.
sourcepub async fn crate_downloads(
&self,
crate_name: &str
) -> Result<CrateDownloads, Error>
pub async fn crate_downloads( &self, crate_name: &str ) -> Result<CrateDownloads, Error>
Retrieve download stats for a crate.
sourcepub async fn crate_owners(&self, name: &str) -> Result<Vec<User>, Error>
pub async fn crate_owners(&self, name: &str) -> Result<Vec<User>, Error>
Retrieve the owners of a crate.
sourcepub async fn crate_reverse_dependencies_page(
&self,
crate_name: &str,
page: u64
) -> Result<ReverseDependencies, Error>
pub async fn crate_reverse_dependencies_page( &self, crate_name: &str, page: u64 ) -> Result<ReverseDependencies, Error>
Get a single page of reverse dependencies.
Note: if the page is 0, it is coerced to 1.
sourcepub async fn crate_reverse_dependencies(
&self,
crate_name: &str
) -> Result<ReverseDependencies, Error>
pub async fn crate_reverse_dependencies( &self, crate_name: &str ) -> Result<ReverseDependencies, Error>
Load all reverse dependencies of a crate.
Note: Since the reverse dependency endpoint requires pagination, this will result in multiple requests if the crate has more than 100 reverse dependencies.
sourcepub async fn crate_reverse_dependency_count(
&self,
crate_name: &str
) -> Result<u64, Error>
pub async fn crate_reverse_dependency_count( &self, crate_name: &str ) -> Result<u64, Error>
Get the total count of reverse dependencies for a given crate.
Retrieve the authors for a crate version.
sourcepub async fn crate_dependencies(
&self,
crate_name: &str,
version: &str
) -> Result<Vec<Dependency>, Error>
pub async fn crate_dependencies( &self, crate_name: &str, version: &str ) -> Result<Vec<Dependency>, Error>
Retrieve the dependencies of a crate version.
sourcepub async fn full_crate(
&self,
name: &str,
all_versions: bool
) -> Result<FullCrate, Error>
pub async fn full_crate( &self, name: &str, all_versions: bool ) -> Result<FullCrate, Error>
Retrieve all available information for a crate, including download stats, owners and reverse dependencies.
The all_versions
argument controls the retrieval of detailed version
information.
If false, only the data for the latest version will be fetched, if true,
detailed information for all versions will be available.
Note: Each version requires two extra requests.
sourcepub async fn crates(&self, query: CratesQuery) -> Result<CratesPage, Error>
pub async fn crates(&self, query: CratesQuery) -> Result<CratesPage, Error>
Retrieve a page of crates, optionally constrained by a query.
If you want to get all results without worrying about paging,
use [all_crates
].
sourcepub fn crates_stream(&self, filter: CratesQuery) -> CrateStream
pub fn crates_stream(&self, filter: CratesQuery) -> CrateStream
Get a stream over all crates matching the given CratesQuery
.