speedrun-api

Crates.iospeedrun-api
lib.rsspeedrun-api
version1.3.0
sourcesrc
created_at2021-09-17 04:04:07.364607
updated_at2023-05-31 20:26:05.218421
descriptionA wrapper for the speedrun.com REST API
homepage
repositoryhttps://github.com/saintdev/speedrun-api
max_upload_size
id452614
size204,219
(saintdev)

documentation

README

Speedrun-Api | A Rust wrapper for the Speedrun.com API

Endpoints are available under the api module. Endpoints can be constructed using a "builder" pattern. To use an endpoint you can query it using the Query or AsyncQuery traits. Paginated endpoints can be queried using the methods on the PagedEndpointExt trait.

All endpoints return types of the caller's choosing that implement the serde Deserialize trait. Callers are suggested to define their own types for obtaining data from the API. This gives more control to the caller on the exact fields that get deserialized, along with being more adaptable to possible api changes. Sample types ARE provided in the types module.

Async Example


use speedrun_api::{
    api::{
        leaderboards::FullGameLeaderboard,
        AsyncQuery,
    },
    error::SpeedrunApiResult,
    SpeedrunApiBuilder,
    types,
}

#[tokio::main]
pub async fn main() -> SpeedrunApiResult<()> {
    // Create a new async client
    let client = SpeedrunApiBuilder::new().build_async()?;

    // Build a new endpoint
    // This gets the "All Campaigns" leaderboard for Age of Empires II.
    let endpoint = FullGameLeaderboard::builder()
        .game("xldev513")
        .category("rklg3rdn")
        .build()
        .unwrap();

    // Query the endpoint using `client`
    let leaderboard: types::Leaderboard = endpoint.query_async(&client).await?;
}

See examples for more examples. Including paginated endpoints.

Design Notes

The design is based on the blog post Designing Rust bindings for REST APIs by Ben Boeckel, and the gitlab crate.

Commit count: 90

cargo fmt