https://github.com/dvcol/mal-http-client
Fetch based http client for MyAnimeList API
https://github.com/dvcol/mal-http-client
Last synced: 4 months ago
JSON representation
Fetch based http client for MyAnimeList API
- Host: GitHub
- URL: https://github.com/dvcol/mal-http-client
- Owner: dvcol
- License: mit
- Created: 2024-08-06T11:54:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-18T19:59:23.000Z (almost 2 years ago)
- Last Synced: 2025-11-21T13:05:54.305Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 258 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
@dvcol/mal-http-client
> 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
```sh
pnpm install
```
## Usage
```sh
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](https://github.com/dvcol/mal-http-client/blob/main/lib/api/mal-api.endpoints.ts#L25) object with all supported endpoints, as well as a [minimal api](https://github.com/dvcol/mal-http-client/blob/main/lib/api/mal-api-minimal.endpoints.ts) object with only the essential authentication endpoints.
You can also import any [endpoint by common scope](https://github.com/dvcol/mal-http-client/tree/main/lib/api/endpoints).
```ts
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: '',
client_secret: '',
redirect_uri: '',
endpoint: Config.endpoint,
TokenTTL: Config.TokenTTL,
RefreshTokenTTL: Config.RefreshTokenTTL,
useragent: '',
corsProxy: '',
corsPrefix: '',
};
const initAuthentication = {}
const malClient = new MalClient(malClientSettings, initAuthentication, malUsedApi);
```
### Features
[//]: # (TODO update this section)
* [Built-in cache support](https://github.com/dvcol/mal-http-client/blob/862718a3a51083a5f63f1ab15cc1e9aaf1b081af/lib/clients/mal-client.test.ts#L79-L155) (per client, endpoint, or query)
* [Extensible cache store](https://github.com/dvcol/mal-http-client/blob/862718a3a51083a5f63f1ab15cc1e9aaf1b081af/lib/clients/mal-client.test.ts#L135-L154) (in-memory, local storage, etc.)
* [Event observer](https://github.com/dvcol/base-http-client/blob/ed17c369f3cdf93656568373fc2dba841050e427/lib/client/base-client.test.ts#L486-L575) (request, query, auth)
* [Built-in cancellation support](https://github.com/dvcol/base-http-client/blob/ed17c369f3cdf93656568373fc2dba841050e427/lib/client/base-client.test.ts#L691-L758)
* [Code redirect authentication](https://github.com/dvcol/mal-http-client/blob/862718a3a51083a5f63f1ab15cc1e9aaf1b081af/lib/clients/mal-client.ts#L40-L130)
* [Token refresh](https://github.com/dvcol/mal-http-client/blob/862718a3a51083a5f63f1ab15cc1e9aaf1b081af/lib/clients/mal-client.ts#L132-L170)
### Documentation
See [Mal API documentation](https://myanimelist.net/apiconfig/references/api/v2) for more information.
## Author
* Github: [@dvcol](https://github.com/dvcol)
## 📝 License
This project is [MIT](https://github.com/dvcol/mal-http-client/blob/master/LICENSE) licensed.