Awesome
pokeapi-go
Wrapper for Poke API, written in Go. Supports PokeAPI v2.
Documentation
Full API documentation can be found at Poke API.
Getting Started
go get github.com/mtslzr/pokeapi-go
import "github.com/mtslzr/pokeapi-go"
Endpoints
Berries
<details> <summary>Berries</summary>Get Berries
b := pokeapi.Resource("berry")
Get Berry
Must pass an ID (e.g. "1") or name (e.g. "cheri").
b := pokeapi.Berry("cheri")
</details>
<details>
<summary>Berry Firmness</summary>
Get Berry Firmnesses
b := pokeapi.Resource("berry-firmness")
Get Berry Firmness
Must pass an ID (e.g. "1") or name (e.g. "very-soft").
b := pokeapi.BerryFirmness("very-soft")
</details>
<details>
<summary>Berry Flavors</summary>
Get Berry Flavors
b := pokeapi.Resource("berry-flavor")
Get Berry Flavor
Must pass an ID (e.g. "1") or name (e.g. "spicy").
b := pokeapi.BerryFlavor("spicy")
</details>
Contests
<details> <summary>Contest Types</summary>Get Contest Types
c := pokeapi.Resource("berry")
Get Contest Type
Must pass an ID (e.g. "1") or name (e.g. "cool").
c := pokeapi.ContestType("cool")
</details>
<details>
<summary>Contest Effects</summary>
Get Contest Effects
c := pokeapi.Resource("contest-effect")
Get Contest Effect
Must pass an ID (e.g. "1").
c := pokeapi.ContestEffect("1")
</details>
<details>
<summary>Super Contest Effects</summary>
Get Super Contest Effects
c := pokeapi.Resource("super-contest-effect")
Get Super Contest Effect
Must pass an ID (e.g. "1").
c := pokeapi.SuperContestEffect("1")
</details>
Encounters
<details> <summary>Encounter Methods</summary>Get Encounter Methods
e := pokeapi.Resource("encounter-method")
Get Encounter Method
Must pass an ID (e.g. "1") or name (e.g. "walk").
e := pokeapi.EncounterMethod("walk")
</details>
<details>
<summary>Encounter Conditions</summary>
Get Encounter Conditions
e := pokeapi.Resource("encounter-condition")
Get Encounter Condition
Must pass an ID (e.g. "1") or name (e.g. "swarm").
e := pokeapi.EncounterCondition("swarm")
</details>
<details>
<summary>Encounter Condition Values</summary>
Get Encounter Condition Values
e := pokeapi.Resource("encounter-condition-value")
Get Encounter Condition Value
Must pass an ID (e.g. "1") or name (e.g. "swarm-yes").
e := pokeapi.EncounterConditionValue("swarm-yes")
</details>
Evolution
<details> <summary>Evolution Chains</summary>Get Evolution Chains
e := pokeapi.Resource("evolution-chain")
Get Evolution Chain
Must pass an ID (e.g. "1").
e := pokeapi.EvolutionChain("1")
</details>
<details>
<summary>Evolution Triggers</summary>
Get Evolution Triggers
e := pokeapi.Resource("evolution-trigger")
Get Evolution Trigger
Must pass an ID (e.g. "1") or name (e.g. "level-up").
e := pokeapi.EvolutionTrigger("level-up")
</details>
Games
<details> <summary>Generations</summary>Get Generations
g := pokeapi.Resource("generation")
Get Generation
Must pass an ID (e.g. "1") or name (e.g. "generation-i").
g := pokeapi.Generation("generation-i")
</details>
<details>
<summary>Pokedex</summary>
Get All Pokedex
g := pokeapi.Resource("pokedex")
Get Single Pokedex
Must pass an ID (e.g. "1") or name (e.g. "national").
g := pokeapi.Pokedex("national")
</details>
<details>
<summary>Versions</summary>
Get Versions
g := pokeapi.Resource("version")
Get Version
Must pass an ID (e.g. "1") or name (e.g. "red").
g := pokeapi.Version("red")
</details>
<details>
<summary>Version Groups</summary>
Get Version Groups
g := pokeapi.Resource("version-group")
Get Version Group
Must pass an ID (e.g. "1") or name (e.g. "red-blue").
g := pokeapi.VersionGroup("red-blue")
</details>
Items
<details> <summary>Items</summary>Get Items
i := pokeapi.Resource("item")
Get Item
Must pass an ID (e.g. "1") or name (e.g. "master-ball").
i := pokeapi.Item("master-ball")
</details>
<details>
<summary>Item Attributes</summary>
Get Item Attributes
i := pokeapi.Resource("item-attribute")
Get Item Attribute
Must pass an ID (e.g. "1") or name (e.g. "countable").
i := pokeapi.ItemAttribute("countable")
</details>
<details>
<summary>Item Categories</summary>
Get Item Ctegories
i := pokeapi.Resource("item-category")
Get Item Category
Must pass an ID (e.g. "1") or name (e.g. "stat-boosts").
i := pokeapi.ItemCategory("stat-boosts")
</details>
<details>
<summary>Item Fling Effects</summary>
Get Item Fling Effects
i := pokeapi.Resource("item-fling-effect")
Get Item Fling Effect
Must pass an ID (e.g. "1") or name (e.g. "badly-poison").
i := pokeapi.ItemFlingEffect("badly-poison")
</details>
<details>
<summary>Item Pockets</summary>
Get Item Pockets
i := pokeapi.Resource("item-pocket")
Get Item Pocket
Must pass an ID (e.g. "1") or name (e.g. "misc").
i := pokeapi.ItemPocket("misc")
</details>
Locations
<details> <summary>Locations</summary>Get Locations
l := pokeapi.Resource("location")
Get Location
Must pass an ID (e.g. "1") or name (e.g. "canalave-city").
l := pokeapi.Location("canalave-city")
</details>
<details>
<summary>Location Areas</summary>
Get Location Areas
l := pokeapi.Resource("location-area")
Get Location Area
Must pass an ID (e.g. "1") or name (e.g. "canalave-city-area").
l := pokeapi.LocationArea("canalave-city-area")
</details>
<details>
<summary>Pal Park Areas</summary>
Get Pal Park Areas
l := pokeapi.Resource("pal-park-area")
Get Pal Park Area
Must pass an ID (e.g. "1") or name (e.g. "forest").
l := pokeapi.PalParkArea("forest")
</details>
<details>
<summary>Regions</summary>
Get Regions
l := pokeapi.Resource("region")
Get Region
Must pass an ID (e.g. "1") or name (e.g. "kanto").
l := pokeapi.Region("kanto")
</details>
Machines
<details> <summary>Machines</summary>Get Machines
m := pokeapi.Resource("machine")
Get Machine
Must pass an ID (e.g. "1").
m := pokeapi.Machine("1")
</details>
Moves
<details> <summary>Moves</summary>Get Moves
m := pokeapi.Resource("move")
Get Move
Must pass an ID (e.g. "1") or name (e.g. "pound").
m := pokeapi.Move("pound")
</details>
<details>
<summary>Move Ailments</summary>
Get Move Ailments
m := pokeapi.Resource("move-ailment")
Get Move Ailment
Must pass an ID (e.g. "1") or name (e.g. "paralysis").
m := pokeapi.MoveAilment("paralysis")
</details>
<details>
<summary>Move Battle Styles</summary>
Get Move Battle Styles
m := pokeapi.Resource("move-battle-style")
Get Move Battle Style
Must pass an ID (e.g. "1") or name (e.g. "attack").
m := pokeapi.MoveBattleStyle("attack")
</details>
<details>
<summary>Move Categories</summary>
Get Move Categories
m := pokeapi.Resource("move-catgory")
Get Move Category
Must pass an ID (e.g. "1") or name (e.g. "ailment").
m := pokeapi.MoveCategory("ailment")
</details>
<details>
<summary>Move Damage Classes</summary>
Get Move Damage Classes
m := pokeapi.Resource("move-damage-class")
Get Move Damage Class
Must pass an ID (e.g. "1") or name (e.g. "status").
m := pokeapi.MoveDamageClass("status")
</details>
<details>
<summary>Move Learn Methods</summary>
Get Move Learn Methods
m := pokeapi.Resource("move-learn-method")
Get Move Learn Method
Must pass an ID (e.g. "1") or name (e.g. "level-up").
m := pokeapi.MoveLearnMethod("level-up")
</details>
<details>
<summary>Move Targets</summary>
Get Move Targets
m := pokeapi.Resource("move-target")
Get Move Target
Must pass an ID (e.g. "1") or name (e.g. "specific-move").
m := pokeapi.MoveTarget("specific-move")
</details>
Pokemon
<details> <summary>Abilities</summary>Get Abilities
p := pokeapi.Resource("ability")
Get Ability
Must pass an ID (e.g. "1") or name (e.g. "stench").
p := pokeapi.Ability("stench")
</details>
<details>
<summary>Characteristics</summary>
Get Characteristics
p := pokeapi.Resource("characteristic")
Get Characteristic
Must pass an ID (e.g. "1").
p := pokeapi.Characteristic("1")
</details>
<details>
<summary>Egg Groups</summary>
Get Egg Groups
p := pokeapi.Resource("egg-group")
Get Egg Group
Must pass an ID (e.g. "1") or name (e.g. "monster").
p := pokeapi.EggGroup("monster")
</details>
<details>
<summary>Genders</summary>
Get Genders
p := pokeapi.Resource("gender")
Get Gender
Must pass an ID (e.g. "1") or name (e.g. "female").
p := pokeapi.Gender("female")
</details>
<details>
<summary>Growth Rates</summary>
Get Growth Rates
p := pokeapi.Resource("growth-rate")
Get Growth Rate
Must pass an ID (e.g. "1") or name (e.g. "slow").
p := pokeapi.GrowthRate("slow")
</details>
<details>
<summary>Natures</summary>
Get Natures
p := pokeapi.Resource("nature")
Get Nature
Must pass an ID (e.g. "1") or name (e.g. "hardy").
p := pokeapi.Nature("hardy")
</details>
<details>
<summary>Pokeathlon Stats</summary>
Get Pokeathlon Stats
p := pokeapi.Resource("pokeathlon-stat")
Get Pokeathlon Stat
Must pass an ID (e.g. "1") or name (e.g. "speed").
p := pokeapi.PokeathlonStat("speed")
</details>
<details>
<summary>Pokemon</summary>
Get All Pokemon
l := pokeapi.Resource("pokemon")
Get Single Pokemon
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
l := pokeapi.Pokemon("bulabsaur")
</details>
<details>
<summary>Pokemon Colors</summary>
Get Pokemon Colors
p := pokeapi.Resource("pokemon-color")
Get Pokemon Color
Must pass an ID (e.g. "1") or name (e.g. "black").
p := pokeapi.PokemonColor("black")
</details>
<details>
<summary>Pokemon Forms</summary>
Get Pokemon Forms
p := pokeapi.Resource("pokemon-form")
Get Pokemon Form
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
p := pokeapi.PokemonForm("bulabsaur")
</details>
<details>
<summary>Pokemon Habitats</summary>
Get Pokemon Habitats
p := pokeapi.Resource("pokemon-habitat")
Get Pokemon Habitat
Must pass an ID (e.g. "1") or name (e.g. "cave").
p := pokeapi.PokemonHabitat("cave")
</details>
<details>
<summary>Pokemon Shapes</summary>
Get Pokemon Shapes
p := pokeapi.Resource("pokemon-shape")
Get Pokemon Shape
Must pass an ID (e.g. "1") or name (e.g. "ball").
p := pokeapi.PokemonShape("ball")
</details>
<details>
<summary>Pokemon Species</summary>
Get All Pokemon Species
p := pokeapi.Resource("pokemon-species")
Get Single Pokemon Species
Must pass an ID (e.g. "1") or name (e.g. "bulbasaur").
p := pokeapi.PokemonSpecies("bulabsaur")
</details>
<details>
<summary>Stats</summary>
Get Stats
p := pokeapi.Resource("stat")
Get Stat
Must pass an ID (e.g. "1") or name (e.g. "hp").
p := pokeapi.Stat("hp")
</details>
<details>
<summary>Types</summary>
Get Types
p := pokeapi.Resource("type")
Get Type
Must pass an ID (e.g. "1") or name (e.g. "normal").
p := pokeapi.Type("normal")
</details>
Utility
<details> <summary>Languages</summary>Get Languages
u := pokeapi.Resource("language")
Get Language
Must pass an ID (e.g. "1") or name (e.g. "en").
u := pokeapi.Language("en")
</details>
Additional Options
Resource List Parameters
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).
r := pokeapi.Resource("pokemon")
fmt.Println(len(r.Results)) // 20
fmt.Println(r.Results[0].Name) // "bulbasaur"
</details>
<details>
<summary>Offset</summary>
r := pokeapi.Resource("pokemon", 3)
fmt.Println(len(r.Results)) // 20
fmt.Println(r.Results[0].Name) // "charmander"
</details>
<details>
<summary>Offset and Limit</summary>
r := pokeapi.Resource("pokemon", 6, 10)
fmt.Println(len(r.Results)) // 10
fmt.Println(r.Results[0].Name) // "squirtle"
</details>
Resource List Filters
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()
.
s := pokeapi.Search("pokemon", "saur")
fmt.Println(len(s.Results)) // 4
fmt.Println(s.Results[3].Name) // venusaur-mega
</details>
<details>
<summary>Starts With</summary>
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
</details>
Caching
Calls are automatically cached to cut down on API traffic to PokeAPI, with subsequent calls returning local data.
Clearing Cache
// Clear all existing cache entries.
pokeapi.ClearCache()
Custom Expiration
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
Disable Cache
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