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?;
}
Re-exports§
pub use crate::types::Root;
Modules§
- categories
- Categories
- developers
- Developers
- engines
- Engines
- games
- Games
- gametypes
- Game types
- genres
- Genres
- guests
- Guests
- leaderboards
- Leaderboards
- levels
- Levels
- notifications
- Notifications
- platforms
- Platforms
- profile
- Profile
- publishers
- Publishers
- regions
- Regions
- runs
- Runs
- series
- Series
- users
- Users
- variables
- Variables
Structs§
- Paged
Iter - Iterator type for the
iter
method onPagedEndpointExt
. - Single
Page - Represents a single page of elements.
- Single
Page Builder - Builder for the
SinglePage
endpoint
Enums§
- ApiError
- Errors that occur from API endpoints.
- Categories
Sorting - Sorting options for categories
- Direction
- Sort direction
- Variables
Sorting - Sorting options for variables
Traits§
- Async
Client - A trait representing an asynchronous client which can communicate with speedrun.com
- Async
Query - Asynchronous query made to a client.
- Client
- A trait representing a client which can communicate with speedrun.com
- Pageable
- Marker trait to indicate that an endpoint is pageable.
- Paged
Endpoint Ext - Adapters specific to
Pageable
endpoints. - Query
- Query made to a client.
- Rest
Client - A trait representing a client which can communicate with speedrun.com via REST