5 stable releases
1.3.0 | May 31, 2023 |
---|---|
1.2.1 | Sep 10, 2022 |
1.2.0 | Aug 28, 2022 |
1.1.1 | Jul 8, 2022 |
1.0.0 | Sep 17, 2021 |
#5 in #speedrun
31 downloads per month
150KB
4K
SLoC
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.
Dependencies
~5–18MB
~231K SLoC