Skip to content

saintdev/speedrun-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Rust API for speedrun.com

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages