API Pokemon Tutorial For BAIS Poké Gym Leader Joel
Purpose and Intention
Some purposes for using this api tutorial are programmatically pulling poke stats instead of manually looking them up. Maybe you could use this info to build those Pokedeck apps or maybe one of those “what Pokemon are you?” Buzzfeed quizzes. I feel like I identify with Jiggly Puff.
I intend to give you a solid tutorial that retrieves Pokemon with specific features like the type of Pokemon etc.
Step 1: Load These Packages
library(httr)library(jsonlite)library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ purrr::flatten() masks jsonlite::flatten()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Step 2: The Endpoint
# PokeAPI requires no api key just the end point like alwayspokeendpoint <-"https://pokeapi.co/api/v2/"# first set up the end point
# This function loading the URL with GET creates the URL into something R friendly we can use and we look at the structure here with the names function.
Step 4: Pikachu Fun Example DEMO
# now we are doing the same thing, but for Pikachupikachu_url <-paste0(pokeendpoint, "pokemon/pikachu")pikachujson <-GET(pikachu_url) %>%content(as ="text", encoding ="UTF-8") %>%fromJSON()# Now we can build our Pikachu yaypokemonid <-data.frame(name = pikachujson$name,height = pikachujson$height,weight = pikachujson$weight,type = pikachujson$types$type$name)pokemonid