PokéAPI's Request Format
Unlike other APIs, the PokéAPI does not require a security token or key of any sort. The API is free to use for any user, with the only restriction being that only 500 calls can be made per day
on a single database entry per IP address. Note also that PokéAPI only allows GET requests.
PokéAPI contains many different methods, a list of which can be found here. The format of a PokéAPI request looks like this:
http://pokeapi.co/api/v2/pokemon-species/eevee
. In this call, we are using version 2 of the API, containing information up to the 7th Generation of Pokémon games. The specific method we are using is the pokemon-species
method, which contains many useful information about each species. The specific species we are looking at is the Pokémon Eevee. PokéAPI also allows calls based on
the Pokémon's National Dex number. Therefore, I could reach the same page by accessing http://pokeapi.co/api/v2/pokemon-species/133
Demo Code Walkthrough
Let's focus now on the GET request portion of the demo Pokédex code.
Let's look at the HTML code.
Note that we define a fieldset, and that the two impotant
id
sections in the fieldset
are
pokemonName
, which is a text input form, and
pokeSubmit
, which is a
submit button. These two
id
's will be used by JavaScript to allow any user to submit
information and make a GET request to the PokéAPI.
In the JavaScript code, we see two functions: bindButtons()
, which on page load tells the pokeSubmit
button to call the second function, pokemonAPI()
.
The first code block in this function clears the screen whenever a new request is sent, the second code block defines the specific method we will use for this function, http://pokeapi.co/api/v2/pokemon-species/
The third code block defines an asynchronous GET request using AJAX, and sends the user's input in pokemonName
along with the address
to the PokéAPI server.
By sending this code segment to the PokéAPI server, the server will respond with a JSON format response which will look like the response from the previous example.
What's Next?
How that we have the basics of the GET request down, we will look at what we need tqo do in order to read and process the server's JSON response. We will continue to look at the demo code for this site's
example Pokédex.