Add the Pokémon client
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.ts
importPokedex
from the Pokémon library, and create an instance of the Pokémon client. Do this within therun
function so that your code will be able to use it when it runs.Use the
getPokemonByName
method 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:
Run
npm run build && npm run start
.
You should see something like this logged - except that the printed object should include the whole tyranitar
object.
This shows the Pokémon client works, so you can remove the logic for fetching and logging out tyranitar
.
Last updated