marvel-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

marvel-ts

An unofficial TypeScript wrapper for Marvel Comics API. Suitable for client and server-side usage.

Install

npm i marvel-ts

Usage

Prerequisites

Import

import { MarvelAPI } from 'marvel-ts';

Instantiate

For client-side / browser you only need to provide your public key.

const PUBLIC_KEY = 'MY_PUBLIC_KEY';

const marvelAPI = new MarvelAPI(PUBLIC_KEY);

For server-side you will need to provide your public and private key.

const PUBLIC_KEY = 'MY_PUBLIC_KEY';
const PRIVATE_KEY = 'MY_PRIVATE_KEY';

const marvelAPI = new MarvelAPI(PUBLIC_KEY, PRIVATE_KEY);

You can also pass in rateLimit options. By default, the wrapper does not apply a rate limit.

const PUBLIC_KEY = 'MY_PUBLIC_KEY';
const PRIVATE_KEY = 'MY_PRIVATE_KEY';

const marvelAPI = new MarvelAPI(PUBLIC_KEY, PRIVATE_KEY, { maxRequests: 4, perMilliseconds: 1000, maxRPS: 4 });

Call Endpoint

All endpoints described in the API documentation are available. For example:

const response = await marvelAPI.getCharacters();

Getting Data

The response from endpoints are typed to mirror those from the documentation. To get the results of the call, use destructuring. For example:

const response = await marvelAPI.getCharacters();

const { data: { results } } = response;

const character = results[0];

Using parameters

All endpoints which do not call for a identifier e.g characterId, can optionally be passed parameters. See documentation for more details.

const response = await marvelAPI.getCharacters({ nameStartsWith: "spider", limit: 5 });

Package Sidebar

Install

npm i marvel-ts

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

165 kB

Total Files

291

Last publish

Collaborators

  • achan42