Crates.io | mal-api |
lib.rs | mal-api |
version | 2.0.2 |
source | src |
created_at | 2023-07-21 00:02:24.177375 |
updated_at | 2024-05-10 03:51:01.593998 |
description | An asynchronous MyAnimeList (MAL) API library for Rust |
homepage | |
repository | https://github.com/dobecad/mal-rs |
max_upload_size | |
id | 921889 |
size | 182,379 |
An asynchronous MyAnimeList (MAL) API library for Rust.
forum
and user
featuresuse dotenvy;
use mal_api::anime_common_fields;
use mal_api::oauth::MalClientId;
use mal_api::prelude::*;
#[tokio::main]
async fn main() {
// See the .env.example for which
// environment variables you are expected to define
dotenvy::dotenv().ok();
let client_id = MalClientId::try_from_env().unwrap();
let api_client = AnimeApiClient::from(&client_id);
let fields = anime_common_fields!(
AnimeField::id,
AnimeField::num_episodes,
AnimeField::title,
);
// Example using the builder pattern.
// The `builder(args...)` method will only take
// the required arguments for the specific API endpoint, while the
// other builder instance methods will build up the optional arguments
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);
}
// Example iterating through pages
let result = api_client.next(&result).await.unwrap();
println!("Next result: {}", &result);
let result = api_client.prev(&result).await.unwrap();
println!("Prev result: {}", &result);
// Manga API example
let api_client = MangaApiClient::from(&client_id);
let fields = mal_api::manga::all_common_fields();
// Example using `new` pattern. Not recommended, but available
let nsfw = false;
let limit = Some(5);
let query = GetMangaList::new("one", 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.
Not all variants for particular fields are documented in the MAL API specification. This is expected since the MAL v2 API is still in beta. If a request fails because of an unexpected variant, please open an issue and describe what query you submitted which revealed the new variant.
This project is licensed under the MIT license