Skip to content

DavidQF555/MAL.js

Repository files navigation

MAL.js

A strongly-typed TypeScript wrapper for the official MyAnimeList API.

Installation

npm install @davidqf555/mal.js

Usage

A client ID can be registered here.

The documentation for the API can be found here.

Example

import MALClient, { FieldsParser } from '@davidqf555/mal.js';

// Create client to access MyAnimeList API
const client = new MALCLient(client_id, client_secret);

// Generate URL for client to authenticate with randomly generated verifer
const { url, code_verifier } = client.requestAuthorization();

// Retrieve token after client authenticates and receives code
const { access_token } = await client.retrieveAuthorizationToken(code, code_verifier);

// Get anime list from a query
const { data } = await client.getAnimeList({ q: 'Sword Art Online', fields: new FieldsParser({ mean: true, rank: true }) });

// Get user anime list of access token owner
const { data } = await client.getUserAnimeList('@me', { status: 'watching' }, access_token);

Client Methods

There is support for user authentication and every documented endpoint.

User Authentication

The supported user authentication methods follow the OAuth 2.0 procedure outlined in the MyAnimeList API documentation.

Name Description
requestAuthorization Uses/Generates a code verifier to create a link for the user to authenticate
retrieveAuthorizationToken Uses the code from the user redirect after authentication to generate both a refresh and access token
refreshAuthorizationToken Uses a refresh token to refresh both the access and refresh tokens

Endpoint Methods

Each method corresponds to a documented endpoint in the MyAnimeList API.

Name Endpoint
getAnimeList GET /anime
getAnimeDetails GET /anime/{anime_id}
getAnimeRanking GET /anime/ranking
getSeasonalAnime GET /anime/season/{year}/{season}
getSuggestedAnime GET /anime/suggestions
updateAnimeListStatus PATCH /anime/{anime_id}/my_list_status
deleteAnimeListItem DELETE /anime/{anime_id}/my_list_status
getUserAnimeList GET /users/{user_name}/animelist
getForumBoards GET /forum/boards
getForumTopicDetails GET /forum/topic/{topic_id}
getForumTopics GET /forum/topics
getMangaList GET /manga
getMangaDetails GET /manga/{manga_id}
getMangaRanking GET /manga/ranking
updateMangaListStatus PATCH /manga/{manga_id}/my_list_status
deleteMangaListItem DELETE /manga/{manga_id}/my_list_status
getUserMangaList GET /users/{user_name}/mangalist
getUserInfo GET /users/{user_name}