Add the Pokémon client
Fetch Pokémon data in your Pandium TypeScript integration by installing a Pokédex client, initializing it in code, and calling it to retrieve a test Pokémon before wiring real logic.
A client is a class with methods that allow you to interact a particular API, e.g. making asynchronous requests to fetch and post records. You will import the PokéAPI's client from a library.
At the moment the code doesn't have any Pokémon information to work with, so let's set up a Pokémon client that will fetch our first Pokémon of the day!
Run
npm install pokedex-promise-v2 --save.
The docs for this library show how to create an instance of a Pokémon client.
In
src/index.tsimportPokedexfrom the Pokémon library, and create an instance of the Pokémon client. Do this within themainfunction so that your code will be able to use it when it runs.Use the
getPokemonByNamemethod from your instance of the Pokémon client to fetch a Pokémon by name .
At this point your src/index.ts should look like this:
import * as dotenv from 'dotenv'
dotenv.config({ quiet: true })
import log4js from 'log4js'
import Pokedex from 'pokedex-promise-v2'
import { Pandium } from './lib.js'
const logger = log4js.getLogger('index')
const main = async () => {
const pandium = Pandium.fromEnv()
logger.info(`This run is in mode: ${pandium.runMode()}`)
logger.info(`Tenant configs: ${JSON.stringify(pandium.config)}`)
const pokeClient = new Pokedex()
const tyranitar = await pokeClient.getPokemonByName('tyranitar')
logger.info(tyranitar)
}
main().then(
() => {},
() => {
process.exitCode = 1
}
)Run
pandium local build && pandium local run <tenant-id>.
You should see something like this logged - except that the printed object should include the whole tyranitar object.
Notice that the tenant configs are now empty, because your tenant is on the release with the PANDIUM.yaml you just cleaned up.
This shows the Pokémon client works, so you can remove the logic for fetching and logging out tyranitar.
Last updated
Was this helpful?