pokeapi

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package pokeapi is the library behind the pokeapi command line: the HTTP client, request shaping, and the typed data models for PokéAPI.

PokéAPI is free and open, no auth required. The client sets a real User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx) with exponential backoff.

Index

Constants

View Source
const Host = "pokeapi.co"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ability added in v0.1.1

type Ability struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	PokemonCount int    `json:"pokemon_count"` // len(pokemon)
	Effect       string `json:"effect"`        // first English effect
	ShortEffect  string `json:"short_effect"`  // first English short_effect
}

Ability is the ability detail from /ability.

type Berry added in v0.1.1

type Berry struct {
	ID         int    `json:"id"          kit:"id"`
	Name       string `json:"name"`
	GrowthTime int    `json:"growth_time"`
	MaxHarvest int    `json:"max_harvest"`
	Firmness   string `json:"firmness"`
	GiftType   string `json:"natural_gift_type"`
	GiftPower  int    `json:"natural_gift_power"`
}

Berry is the berry detail from /berry.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to PokéAPI over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) GetAbility added in v0.1.1

func (c *Client) GetAbility(ctx context.Context, nameOrID string) (*Ability, error)

GetAbility fetches the ability record by name or id.

func (*Client) GetBerry added in v0.1.1

func (c *Client) GetBerry(ctx context.Context, nameOrID string) (*Berry, error)

GetBerry fetches the berry record by name or id.

func (*Client) GetGeneration added in v0.1.1

func (c *Client) GetGeneration(ctx context.Context, nameOrID string) (*Generation, error)

GetGeneration fetches the generation record by name or id.

func (*Client) GetItem added in v0.1.1

func (c *Client) GetItem(ctx context.Context, nameOrID string) (*Item, error)

GetItem fetches the item record by name or id.

func (*Client) GetMove added in v0.1.1

func (c *Client) GetMove(ctx context.Context, nameOrID string) (*Move, error)

GetMove fetches the move record by name or id.

func (*Client) GetPokemon added in v0.1.1

func (c *Client) GetPokemon(ctx context.Context, nameOrID string) (*Pokemon, error)

GetPokemon fetches the full detail record for the named or numbered Pokémon.

func (*Client) GetSpecies added in v0.1.1

func (c *Client) GetSpecies(ctx context.Context, nameOrID string) (*Species, error)

GetSpecies fetches the species record for the named or numbered Pokémon.

func (*Client) GetType added in v0.1.1

func (c *Client) GetType(ctx context.Context, nameOrID string) (*Type, error)

GetType fetches the type record by name or id.

func (*Client) List added in v0.1.1

func (c *Client) List(ctx context.Context, limit, offset int) ([]PokemonListItem, error)

List returns PokemonListItems starting at offset. Rank is 1-based (offset+index+1). Pass limit=0 for API default of 20.

type Config added in v0.1.1

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the pokeapi driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Generation added in v0.1.1

type Generation struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	MainRegion   string `json:"main_region"`
	PokemonCount int    `json:"pokemon_count"` // len(pokemon_species)
	TypeCount    int    `json:"type_count"`    // len(types)
}

Generation is the generation detail from /generation.

type Item added in v0.1.1

type Item struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	Cost       int    `json:"cost"`
	FlingPower int    `json:"fling_power"`
	Category   string `json:"category"`
	Effect     string `json:"effect"` // first English effect
}

Item is the item detail from /item.

type Move added in v0.1.1

type Move struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Power       int    `json:"power"`
	Accuracy    int    `json:"accuracy"`
	PP          int    `json:"pp"`
	Type        string `json:"type"`
	DamageClass string `json:"damage_class"`
	Effect      string `json:"effect"` // first English effect
}

Move is the move detail from /move.

type Pokemon added in v0.1.1

type Pokemon struct {
	ID             int      `json:"id"`
	Name           string   `json:"name"`
	Height         int      `json:"height"` // decimeters
	Weight         int      `json:"weight"` // hectograms
	BaseExperience int      `json:"base_experience"`
	Types          []string `json:"types"`
	Abilities      []string `json:"abilities"`
	HP             int      `json:"hp"`
	Attack         int      `json:"attack"`
	Defense        int      `json:"defense"`
	SpAttack       int      `json:"sp_attack"`
	SpDefense      int      `json:"sp_defense"`
	Speed          int      `json:"speed"`
	SpriteURL      string   `json:"sprite_url"` // front_default sprite
	URL            string   `json:"url"`        // https://pokeapi.co/api/v2/pokemon/{id}/
}

Pokemon is the full detail record for one Pokémon.

type PokemonListItem added in v0.1.1

type PokemonListItem struct {
	Rank int    `json:"rank"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

PokemonListItem is one row from the /pokemon list endpoint.

type Species added in v0.1.1

type Species struct {
	ID            int    `json:"id"`
	Name          string `json:"name"`
	IsLegendary   bool   `json:"is_legendary"`
	IsMythical    bool   `json:"is_mythical"`
	CaptureRate   int    `json:"capture_rate"`
	BaseHappiness int    `json:"base_happiness"`
	Color         string `json:"color"`
	Generation    string `json:"generation"`
	FlavorText    string `json:"flavor_text"` // first English entry
}

Species is the Pokémon species record from /pokemon-species.

type Type added in v0.1.1

type Type struct {
	ID               int      `json:"id"`
	Name             string   `json:"name"`
	PokemonCount     int      `json:"pokemon_count"`      // len(pokemon)
	SuperEffective   []string `json:"super_effective"`    // double_damage_to names
	WeakTo           []string `json:"weak_to"`            // double_damage_from names
	NotVeryEffective []string `json:"not_very_effective"` // half_damage_to names
	NoEffect         []string `json:"no_effect"`          // no_damage_to names
}

Type is the Pokémon type info from /type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL