Skip to content

Instantly share code, notes, and snippets.

@eevee
Last active December 13, 2015 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevee/4942613 to your computer and use it in GitHub Desktop.
Save eevee/4942613 to your computer and use it in GitHub Desktop.
Pokédex API

RIGHT SO there are several use cases here; essentially we want to make the entire website navigable via API.

which means you should be able to REQUEST:

  • lookup a single Pokémon
  • retrieve a single Pokémon unambiguously -- by identifier or id
  • search across all manner of properties

and RETRIEVE:

  • any property
  • in any language
  • in any version

By the way a "locus" is a Primary Thing (i.e. something that has a dedicated page on veekun) and a "property" is a... property. yeah.

Dumb example

A simple API response might look like this:

GET /api/pokemon/eevee

# these are "default" properties
{
    "identifier": "eevee",
    "generation": 1,
    "types": [
        "normal",
    ],
    # ...
}

Requests

Conceptually, there are three ways to make requests.

  • Directly with an identifier (and required locus category). This may:
    • Find exactly one locus.
    • Find nothing.
  • Lookup (with optional language and locus category). This may:
    • Find any number of loci by exact match, due to repeated names across languages or categories.
    • Find multiple loci by fuzzy match.
    • Find nothing.
  • Search. This may:
    • Find any number of loci.
    • Find nothing.
    • Require more information. But more on that later.

Responses

These are bags of properties, as seen in the example, though there are a few other considerations.

  • Responses can contain any collection of properties.
  • If a property happens to be another locus (e.g. a Pokémon's types), that locus can also be fetched at the same time.
  • Responses can be limited by language, to determine which strings of e.g. flavor text are returned.
  • Responses can be limited by version, to determine e.g. which movesets are returned.

Umm unsorted

Direct URLS

As seen above, /api/pokemon/eevee and similar URLs will produce JSON containing a reasonable "default" set of properties.

Lookup

Simple properties

identifier is a simple property: it's a scalar, a string. You can't even substring-match against it, because we treat it as an indivisible atom.

Some stuff about properties:

  • Properties can be loci themselves—for example, a type is itself a locus.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment