mal-api
An asynchronous MyAnimeList (MAL) API library for Rust.
Features
- Type-safe query builder
- Type-safe responses
- Pagination through responses
- Support for accessing all of MAL's endpoints (Anime, Manga, Forum, and User)
- To access the Forum and User endpoints, enable the
forum
and user
features
- OAuth2 access token retrieval and management
Example
use dotenvy;
use mal_api::anime_common_fields;
use mal_api::oauth::MalClientId;
use mal_api::prelude::*;
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let client_id = MalClientId::from_env().unwrap();
let api_client = AnimeApiClient::from(&client_id);
let fields = anime_common_fields!(
AnimeField::id,
AnimeField::num_episodes,
AnimeField::title,
);
let query = GetAnimeList::builder("One")
.fields(&fields)
.limit(5)
.build()
.unwrap();
let result = api_client.get_anime_list(&query).await.unwrap();
println!("Received response: {}", result);
for entry in result.data.iter() {
println!("Anime Title: {} Anime ID: {}", entry.node.title, entry.node.id);
}
let result = api_client.next(&result).await.unwrap();
println!("Next result: {}", &result);
let result = api_client.prev(&result).await.unwrap();
println!("Prev result: {}", &result);
let api_client = MangaApiClient::from(&client_id);
let fields = mal_api::manga::all_common_fields();
let nsfw = false;
let limit = Some(5);
let query = GetMangaList::new("one".to_string(), nsfw, Some(&fields), limit, None).unwrap();
let result = api_client.get_manga_list(&query).await.unwrap();
println!("Result: {}", result);
}
You can check out the examples directory to see additional usage examples.
License
This project is licensed under the MIT license