Wrapper for Poke API, written in Go. Supports PokeAPI v2.
Full API documentation can be found at Poke API.
go get github.com/mtslzr/pokeapi-go
import "github.com/mtslzr/pokeapi-go"
Berries
b := pokeapi.Resource("berry")
Must pass an ID (e.g. "1") or name (e.g. "cheri").
b := pokeapi.Berry("cheri")
Berry Firmness
b := pokeapi.Resource("berry-firmness")
Must pass an ID (e.g. "1") or name (e.g. "very-soft").
b := pokeapi.BerryFirmness("very-soft")
Berry Flavors
b := pokeapi.Resource("berry-flavor")
Must pass an ID (e.g. "1") or name (e.g. "spicy").
b := pokeapi.BerryFlavor("spicy")
Contest Types
c := pokeapi.Resource("berry")
Must pass an ID (e.g. "1") or name (e.g. "cool").
c := pokeapi.ContestType("cool")
Contest Effects
c := pokeapi.Resource("contest-effect")
Must pass an ID (e.g. "1").
c := pokeapi.ContestEffect("1")
Super Contest Effects
c := pokeapi.Resource("super-contest-effect")
Must pass an ID (e.g. "1").
c := pokeapi.SuperContestEffect("1")
Encounter Methods
e := pokeapi.Resource("encounter-method")
Must pass an ID (e.g. "1") or name (e.g. "walk").
e := pokeapi.EncounterMethod("walk")
Encounter Conditions
e := pokeapi.Resource("encounter-condition")
Must pass an ID (e.g. "1") or name (e.g. "swarm").
e := pokeapi.EncounterCondition("swarm")
Encounter Condition Values
e := pokeapi.Resource("encounter-condition-value")
Must pass an ID (e.g. "1") or name (e.g. "swarm-yes").
e := pokeapi.EncounterConditionValue("swarm-yes")
Evolution Chains
e := pokeapi.Resource("evolution-chain")
Must pass an ID (e.g. "1").
e := pokeapi.EvolutionChain("1")
Evolution Triggers
e := pokeapi.Resource("evolution-trigger")
Must pass an ID (e.g. "1") or name (e.g. "level-up").
e := pokeapi.EvolutionTrigger("level-up")
Generations
g := pokeapi.Resource("generation")
Must pass an ID (e.g. "1") or name (e.g. "generation-i").
g := pokeapi.Generation("generation-i")
Pokedex
g := pokeapi.Resource("pokedex")
Must pass an ID (e.g. "1") or name (e.g. "national").
g := pokeapi.Pokedex("national")
Versions
g := pokeapi.Resource("version")
Must pass an ID (e.g. "1") or name (e.g. "red").
g := pokeapi.Version("red")
Version Groups
g := pokeapi.Resource("version-group")
Must pass an ID (e.g. "1") or name (e.g. "red-blue").
g := pokeapi.VersionGroup("red-blue")
Items
i := pokeapi.Resource("item")
Must pass an ID (e.g. "1") or name (e.g. "master-ball").
i := pokeapi.Item("master-ball")
Item Attributes
i := pokeapi.Resource("item-attribute")
Must pass an ID (e.g. "1") or name (e.g. "countable").
i := pokeapi.ItemAttribute("countable")
Item Categories
i := pokeapi.Resource("item-category")
Must pass an ID (e.g. "1") or name (e.g. "stat-boosts").
i := pokeapi.ItemCategory("stat-boosts")
Item Fling Effects
i := pokeapi.Resource("item-fling-effect")
Must pass an ID (e.g. "1") or name (e.g. "badly-poison").
i := pokeapi.ItemFlingEffect("badly-poison")
Item Pockets
i := pokeapi.Resource("item-pocket")
Must pass an ID (e.g. "1") or name (e.g. "misc").
i := pokeapi.ItemPocket("misc")
Locations
l := pokeapi.Resource("location")
Must pass an ID (e.g. "1") or name (e.g. "canalave-city").
l := pokeapi.Location("canalave-city")
Location Areas
l := pokeapi.Resource("location-area")
Must pass an ID (e.g. "1") or name (e.g. "canalave-city-area").
l := pokeapi.LocationArea("canalave-city-area")
Pal Park Areas
l := pokeapi.Resource("pal-park-area")
Must pass an ID (e.g. "1") or name (e.g. "forest").
l := pokeapi.PalParkArea("forest")
Regions
l := pokeapi.Resource("region")
Must pass an ID (e.g. "1") or name (e.g. "kanto").
l := pokeapi.Region("kanto")
Machines
m := pokeapi.Resource("machine")
Must pass an ID (e.g. "1").
m := pokeapi.Machine("1")
Moves
m := pokeapi.Resource("move")
Must pass an ID (e.g. "1") or name (e.g. "pound").
m := pokeapi.Move("pound")
Move Ailments
m := pokeapi.Resource("move-ailment")
Must pass an ID (e.g. "1") or name (e.g. "paralysis").
m := pokeapi.MoveAilment("paralysis")
Move Battle Styles
m := pokeapi.Resource("move-battle-style")
Must pass an ID (e.g. "1") or name (e.g. "attack").
m := pokeapi.MoveBattleStyle("attack")
Move Categories
m := pokeapi.Resource("move-catgory")
Must pass an ID (e.g. "1") or name (e.g. "ailment").
m := pokeapi.MoveCategory("ailment")
Move Damage Classes
m := pokeapi.Resource("move-damage-class")
Must pass an ID (e.g. "1") or name (e.g. "status").
m := pokeapi.MoveDamageClass("status")
Move Learn Methods
m := pokeapi.Resource("move-learn-method")
Must pass an ID (e.g. "1") or name (e.g. "level-up").
m := pokeapi.MoveLearnMethod("level-up")
Move Targets
m := pokeapi.Resource("move-target")
Must pass an ID (e.g. "1") or name (e.g. "specific-move").
m := pokeapi.MoveTarget("specific-move")
Abilities
p := pokeapi.Resource("ability")
Must pass an ID (e.g. "1") or name (e.g. "stench").
p := pokeapi.Ability("stench")
Characteristics
p := pokeapi.Resource("characteristic")
Must pass an ID (e.g. "1").
p := pokeapi.Characteristic("1")
Egg Groups
p := pokeapi.Resource("egg-group")
Must pass an ID (e.g. "1") or name (e.g. "monster").
p := pokeapi.EggGroup("monster")
Genders
p := pokeapi.Resource("gender")
Must pass an ID (e.g. "1") or name (e.g. "female").
p := pokeapi.Gender("female")
Growth Rates
p := pokeapi.Resource("growth-rate")
Must pass an ID (e.g. "1") or name (e.g. "slow").
p := pokeapi.GrowthRate("slow")
Natures
p := pokeapi.Resource("nature")
Must pass an ID (e.g. "1") or name (e.g. "hardy").
p := pokeapi.Nature("hardy")
Pokeathlon Stats
p := pokeapi.Resource("pokeathlon-stat")
Must pass an ID (e.g. "1") or name (e.g. "speed").
p := pokeapi.PokeathlonStat("speed")
Pokemon
l := pokeapi.Resource("pokemon")
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
l := pokeapi.Pokemon("bulabsaur")
Pokemon Colors
p := pokeapi.Resource("pokemon-color")
Must pass an ID (e.g. "1") or name (e.g. "black").
p := pokeapi.PokemonColor("black")
Pokemon Forms
p := pokeapi.Resource("pokemon-form")
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
p := pokeapi.PokemonForm("bulabsaur")
Pokemon Habitats
p := pokeapi.Resource("pokemon-habitat")
Must pass an ID (e.g. "1") or name (e.g. "cave").
p := pokeapi.PokemonHabitat("cave")
Pokemon Shapes
p := pokeapi.Resource("pokemon-shape")
Must pass an ID (e.g. "1") or name (e.g. "ball").
p := pokeapi.PokemonShape("ball")
Pokemon Species
p := pokeapi.Resource("pokemon-species")
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
p := pokeapi.PokemonSpecies("bulabsaur")
Stats
p := pokeapi.Resource("stat")
Must pass an ID (e.g. "1") or name (e.g. "hp").
p := pokeapi.Stat("hp")
Types
p := pokeapi.Resource("type")
Must pass an ID (e.g. "1") or name (e.g. "normal").
p := pokeapi.Type("normal")
Languages
u := pokeapi.Resource("language")
Must pass an ID (e.g. "1") or name (e.g. "en").
u := pokeapi.Language("en")
When calling pokeapi.Resource()
for any resource list, you can optionally pass up to two integers. The first will be an offset (defaults to zero), and the second will be the limit (defaults two twenty).
Default
r := pokeapi.Resource("pokemon")
fmt.Println(len(r.Results)) // 20
fmt.Println(r.Results[0].Name) // "bulbasaur"
Offset
r := pokeapi.Resource("pokemon", 3)
fmt.Println(len(r.Results)) // 20
fmt.Println(r.Results[0].Name) // "charmander"
Offset and Limit
r := pokeapi.Resource("pokemon", 6, 10)
fmt.Println(len(r.Results)) // 10
fmt.Println(r.Results[0].Name) // "squirtle"
As an alternative to pokeapi.Resource()
, you can use Search to filter resource lists. Pass the endpoint, followed by the search term. Or pass a string starting with ^
to search for items starting with the search team.
result.Count is updated after the search with the new total (to get the full count, use pokeapi.Resource()
.
Search
s := pokeapi.Search("pokemon", "saur")
fmt.Println(len(s.Results)) // 4
fmt.Println(s.Results[3].Name) // venusaur-mega
Starts With
s := pokeapi.Search("pokemon", "^a")
fmt.Println(len(s.Results)) // 44
fmt.Println(s.Results[0].Name) // arbok
s := pokeapi.Search("pokemon", "^bulb")
fmt.Println(len(s.Results)) // 1
fmt.Println(s.Results[0].Name) // bulbasaur
Calls are automatically cached to cut down on API traffic to PokeAPI, with subsequent calls returning local data.
// Clear all existing cache entries.
pokeapi.ClearCache()
Custom cache expiration remains for all calls until changed or unset.
// Set cache expiration to twenty minutes.
pokeapi.CacheSettings.CustomExpire = 20
// Turn custom expiration back off.
pokeapi.CacheSettings.CustomExpire = 0
Please be considerate of PokeAPI and be sure to always operate within this requested limits.
As with custom expiration, this setting remains for all calls until changed or unset.
// Disable checking for cached data
pokeapi.CacheSettings.UseCache = false
// Re-enable checking for cached data
pokeapi.CacheSettings.UseCache = true