1.1.1 • Published 10 months ago

@dvcol/mal-http-client v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Simple fetch based http client for the MyAnimeList API with full typescript support (request and response).

Prerequisites

  • pnpm >=9.0.0
  • node >=20.0.0

Install

pnpm install

Usage

pnpm add @dvcol/mal-http-client

Modular endpoint bundling

Mal-http-client is designed to be modular and flexible. Although it uses static classes, endpoints are instantiated at runtime and can be easily omitted, extended or overridden. If your bundler does not support tree-shaking, you can omit unused endpoints by only importing the ones you need.

By default we provide a full api object with all supported endpoints, as well as a minimal api object with only the essential authentication endpoints. You can also import any endpoint by common scope.

import { MalClient } from '@dvcol/mal-http-client';
import { anime } from '@dvcol/mal-http-client/api/anime';
import { minimalMalApi } from '@dvcol/mal-http-client/api/minimal';
 
import { Config } from '@dvcol/mal-http-client/config';

import type { MalClientSettings } from '@dvcol/mal-http-client/models';


const malUsedApi = {
  ...minimalMalApi,
  anime
};

const malClientSettings: MalClientSettings = {
  client_id: '<Your mal ID>',
  client_secret: '<Your mal secret>',
  redirect_uri: '<Your mal redirect uri>',
  
  endpoint: Config.endpoint,
  TokenTTL: Config.TokenTTL,
  RefreshTokenTTL: Config.RefreshTokenTTL,

  useragent: '<Your user Agent>',
  corsProxy: '<Optional cors Proxy>',
  corsPrefix: '<Optional cors Proxy prefix>',
};

const initAuthentication = {}


const malClient = new MalClient(malClientSettings, initAuthentication, malUsedApi);

Features

Documentation

See Mal API documentation for more information.

Author

📝 License

This project is MIT licensed.