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.
Last updated
Was this helpful?
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.
Last updated
Was this helpful?
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 show how to create an instance of a Pokémon client.
In src/index.ts
import Pokedex
from the Pokémon library, and create an instance of the Pokémon client. Do this within the run
function so that your code will be able to use it when it runs.
Use the 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
.