pokeapi-typescript is a fully-typed SDK for the PokeAPI using Promises, featuring an easy to manage cache which utilises Collections
Via yarn: yarn add pokeapi-typescript
Via npm: npm install pokeapi-typescript
To start using the PokeAPI, import the module. All available endpoints are mounted as static properties of the module.
// ES6 imports
import PokeAPI from "pokeapi-typescript";
// Node.js require
const PokeAPI = require("pokeapi-typescript");
Every endpoint documented in the PokeAPI Docs is available. By default, any data that is fetched will be cached in-memory.
PokeAPI.<Endpoint>.resolve()
retrieves a resource, first checking the internal cache to see if it is available. If no cached resource exists, it will be fetched via the API.
// Using .then()
PokeAPI.Pokemon.resolve(25).then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.resolve(25);
// Using.then()
PokeAPI.Pokemon.resolve("pikachu").then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.resolve("pikachu");
PokeAPI.<Endpoint>.fetch()
will always retrieve a resource via the API, updating any cached resources in the process.
// Using .then()
PokeAPI.Pokemon.fetch(25).then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.fetch(25);
// Using.then()
PokeAPI.Pokemon.fetch("pikachu").then(result => console.log(result));
// Using async/await
const result = await PokeAPI.Pokemon.fetch("pikachu");
PokeAPI.<Endpoint>.get()
will always retrieve a cached resource, returning null if one could not be found. .get()
is synchronous and does not return a Promise.
const result = PokeAPI.Pokemon.get(25);
const result = PokeAPI.Pokemon.get("pikachu");
PokeAPI.<Endpoint>.list()
retrieves the IApiResourceList or INamedApiResourceList for an endpoint.
list()
accepts two parameters for pagination
limit
- Number of results to list. Default 20offset
- Index of result to start listing from. Default 0
// Fetch 1000 Pokemon (all) in a NamedApiResourceList
const resourceList = await PokeAPI.Pokemon.list(1000, 0);
resourceList.results
will contain an array of IApiResource
or INamedApiResource
objects depending on the type of list.
PokeAPI.<Endpoint>.listAll()
functions like the above, but will return the complete list for an endpoint. This is done by making two API calls.
// Fetch 1000 Pokemon (all) in a NamedApiResourceList
const completeResourceList = await PokeAPI.Pokemon.listAll();
- Berry
- BerryFirmness
- BerryFlavors
- ContestType
- ContestEffect
- SuperContestEffect
- EncounterMethod
- EncounterCondition
- EncounterConditionValue
- EvolutionChain
- EvolutionTrigger
- Generation
- Pokedex
- Version
- VersionGroup
- Item
- ItemAttribute
- ItemCategory
- ItemFlingEffect
- ItemPocket
- Location
- LocationArea
- PalParkArea
- Region
- Machine
- Move
- MoveAilment
- MoveBattleStyle
- MoveCategory
- MoveDamageClass
- MoveLearnMethod
- MoveTarget
- Ability
- Characteristic
- EggGroup
- Gender
- GrowthRate
- Nature
- PokeathlonStat
- Pokemon
- PokemonColor
- PokemonForm
- PokemonHabitat
- PokemonShape
- PokemonSpecies
- Stat
- Type
- Language