Crates.io | speedrun-api |
lib.rs | speedrun-api |
version | 1.3.0 |
source | src |
created_at | 2021-09-17 04:04:07.364607 |
updated_at | 2023-05-31 20:26:05.218421 |
description | A wrapper for the speedrun.com REST API |
homepage | |
repository | https://github.com/saintdev/speedrun-api |
max_upload_size | |
id | 452614 |
size | 204,219 |
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.
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.
The design is based on the blog post Designing Rust bindings for REST APIs by Ben Boeckel, and the gitlab crate.