Module speedrun_api::api
source · [−]Expand description
API endpoint modules
All endpoints use a builder pattern to construct their parameters.
Example
use futures::{StreamExt, TryStreamExt};
use serde::Deserialize;
use speedrun_api::{
api::{self, AsyncQuery, PagedEndpointExt},
error::SpeedrunApiResult,
SpeedrunApiBuilder,
};
// The return type for the endpoints we are interested in. More information
// is returned by the endpoints, but you can deserialize only what is needed.
#[derive(Debug, Deserialize)]
struct Game {
names: Names,
weblink: String,
}
#[derive(Debug, Deserialize)]
struct Names {
international: String,
}
#[tokio::main]
pub async fn main() -> SpeedrunApiResult<()> {
// Create a new client
let client = SpeedrunApiBuilder::new().build_async()?;
// Create an endpoint. This endpoint gets Super Mario Sunshine.
let endpoint = api::games::Game::builder().id("v1pxjz68").build().unwrap();
// Call the endpoint. The return type decides how to represent the returned value.
let game: Game = endpoint.query_async(&client).await?;
// Create a paginated endpoint. This retrievs a list of all games.
let paginated_endpoint = api::games::Games::builder().build().unwrap();
// The `PagedEndpointExt` adapters consume the endpoint, so we create a copy.
let async_stream = paginated_endpoint.clone();
// Call the `PagedEndpointExt::stream()` method to get an async Stream of results.
let games: Vec<Game> = async_stream.stream(&client).take(200).try_collect().await?;
// Call the `PagedEndpointExt::single_page()` method to retrieve a single page builder.
// This retrieves 100 results starting at offset 100.
let single_page_endpoint = paginated_endpoint
.single_page()
.offset(100)
.max(100)
.build()
.unwrap();
// This wrapped endpoint can be queried like any normal endpoint, but always returns a
// `Vec<T: Deserialize>`.
let games: Vec<Game> = single_page_endpoint.query_async(&client).await?;
}Modules
Categories
Developers
Engines
Games
Game types
Genres
Guests
Leaderboards
Levels
Notifications
Platforms
Profile
Publishers
Regions
Runs
Series
Users
Variables
Structs
Iterator type for the iter method on PagedEndpointExt.
Represents a single page of elements.
Builder for the SinglePage endpoint
Enums
Errors that occur from API endpoints.
Sorting options for categories
Sort direction
Sorting options for variables
Traits
A trait representing an asynchronous client which can communicate with speedrun.com
Asynchronous query made to a client.
A trait representing a client which can communicate with speedrun.com
Marker trait to indicate that an endpoint is pageable.
Adapters specific to Pageable endpoints.
A trait representing a client which can communicate with speedrun.com via REST