Pokedex API Documentation

Overview

We have provided two web services for you two use on Homework 3: a Pokedex API and a Game Management API. The Pokedex API provides data about each of the 151 Pokemon, including moves, type, and weakness. Each type of query produces output in plain text or JSON format (You can test queries by typing in their URL in your browser’s address bar and seeing the result). If you submit an invalid query, such as one missing a necessary parameter, the request will return an HTTP error code of 400 (Invalid request) rather than the default 200.

The rest of this document provides the necessary information about the endpoints and query types for the requests you will make for your Pokedex assignment.

Pokedex API

Endpoint: https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php

The first web service, pokedex.php, provides data about each of the 151 Pokemon and accepts two different types of “GET” queries, specified using a query string with a parameter.

Query 1: Get Pokemon Names

Request Format: pokedex.php?pokedex=all
Request Type: GET
Returned Data Format: plain text

Description: This first request takes the parameter all and returns a plain text response with a line for all 151 Pokemon names. The Pokemon's full name is followed by its shortname separated by a single ":", as in:

    Full Name:shortname

The shortname is included in the response to specify the base string for the sprite images (which are all .png files). This shortname can also be used for the "pokemon" query parameter in the pokedex.php API (see Query 2 below). This shortname helps handle the few cases when a Pokemon's full name has non-alphabetical characters. For example, the "Mr. Mime" Pokemon has a shortname of "mr-mime" which corresponds to the sprite image at the following location: https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/sprites/mr-mime.png

Each Pokemon's shortname corresponds to the Pokemon’s sprite image (which needs a .png appended) in the https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/sprites/ folder.

Request: https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokedex=all

Output: (abbreviated)



    Abra:abra
    Aerodactyl:aerodactyl
    Alakazam:alakazam
    ...
    Mr. Mime:mr-mime
    ...
    Zubat:zubat
        

Query 2: Get Pokemon Data

Request Format: pokedex.php?pokemon={name}
Request Type: GET
Returned Data Format: JSON

Description: The second request type takes as a parameter any Pokemon name and returns a detailed JSON object containing data about this Pokemon. The returned data will be used to populate a card for that Pokemon.

Request: https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokemon=pikachu

Example Output:



   {
     "name": "Pikachu",
     "shortname": "pikachu",
     "hp": 160,
     "info": {
        "id": 25,
        "type": "electric",
        "weakness": "ground",
        "description": "Melissa's favorite Pokemon! When several Pikachu gather, their electricity could build and cause lightning storms."
     },
     "images": {
     "photo": "images/pikachu.jpg",
     "typeIcon": "icons/electric.jpg",
     "weaknessIcon": "icons/ground.jpg"
    },
    "moves": [
      {
        "name": "Growl",
        "type": "normal"
      },
      {
        "name": "Quick Attack",
        "dp": 40,
        "type": "normal"
      },
      {
        "name": "Thunderbolt",
        "dp": 90,
        "type": "electric"
      }
    ]
        

The values of the returned JSON object include the name of the Pokemon (e.g., Pikachu), shortname (e.g. pikachu - this is the same shortname format as given by the response detailed in Query 1), the type of the Pokmeon (e.g., “electric”), its weakness type (e.g., “ground”), the health points, or hp (e.g., 80), the set of images (photo for the main Pokemon image and typeIcon and weaknessIcon for the type and weakness icon image paths, respectively), and the set of moves (each Pokemon has between 1 and 4 moves; Pikachu has 4). Each move has a type, and moves that do damage have a “dp”, or damage point attribute. Moves that do not have a “dp” attribute (e.g., Growl) affect stats of the player or opponent’s Pokemon, which is handled elsewhere in the program (during the game mode).

Game Management API

Endpoint: https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/game.php

The second web service, game.php, accepts two POST query types to initiate and update the state of a card game.

Query 3: Start Game

Request Format: game.php endpoint with POST parameters of startgame (set to true) and mypokemon
Request Type: POST
Returned Data Format: JSON

Description: The third request you will use initiates a game and passes two parameters, startgame and mypokemon to game.php. In contrast to the first two “GET” requests, this request is a “POST” request. Upon success, the request returns a JSON response of the initial game state (with information for both players’ Pokemon) and unique game id (guid) and player id (pid) for the player to use to access and update the current game state.

Example Request: POST parameters of startgame=true and mypokemon=pikachu

Example Output:



       {
         "guid" : "game_12345abc",
         "pid" : "player_cfe67890",
         "p1" : {
           "name" : "Pikachu",
           "shortname" : "pikachu",
           "hp" : 160,
           "current-hp" : 160,
           "images" : {
             "photo" : "images/pikachu.jpg",
             "typeIcon" : "icons/electric.jpg",
             "weaknessIcon" : "icons/ground.jpg"
           },
           "info": {
             "id": 25,
             "type": "electric",
             "weakness": "ground",
             "description": "Melissa's favorite Pokemon! When several Pikachu gather,
                  their electricity could build and cause lightning storms."
           },
           "moves": [
             {
               "name": "Growl",
               "type": "normal"
             },
             {
               "name": "Quick Attack",
               "dp": 40,
               "type": "normal"
             },
             {
               "name": "Thunderbolt",
               "dp": 90,
               "type": "electric"
             }
           ],
           "buffs": [],
           "debuffs": []
         },
         "p2" : {
           "name" : "Ditto",
           "shortname" : "ditto",
           "hp" : 206,
           "current-hp" : 206,
           "images": {
             "photo": "images/ditto.jpg",
             "typeIcon": "icons/normal.jpg",
             "weaknessIcon": "icons/fighting.jpg"
           },
           "info": {
             "id": 132,
             "type": "normal",
             "weakness": "fighting",
             "description": "Duncan's favorite Pokemon (he has an awesome painting of Ditto on his wall). It can transform
                into anything. When it sleeps, it changes into a stone to avoid being attacked."
           },
           "moves": [
             {
               "name": "Transform",
               "dp": 40,
               "type": "normal"
             }
           ],
           "buffs": [],
           "debuffs": []
         }
       }
        

You may assume that the guid and pid attributes returned are unique to the started game.

Query 4: Play a Move

Request Format: game.php endpoint with POST parameters of guid, pid, and movename
Request Type: POST
Returned Data Format: JSON

Description:This query submits a move played by your Pokemon on the current turn and requires three parameters: move as your Pokemon’s move name, guid as your unique game ID, and pid as your unique player id. The move name should be passed as an all-lowercase string, and if there are any spaces in the move name (e.g., "Quick Attack"), they should be removed when passed as a parameter (e.g., "Quick Attack" would be passed as "quickattack"). The game state is updated by applying that move’s effects to either player (depending on the specific effects of the move). The request will also call the opponent’s move, which may update the health or buffs of your Pokemon. Upon success, the request returns the current game state, including each player’s current Pokemon status and the results of the two moves (yours and the opponents), as a JSON object. If your Pokemon wins the battle as a result of the move, "p2-move" and "p2-result" will be returned as null, indicating p2’s Pokemon did not make a move (they are unable to play anymore in the current game). There is a special case when movename is passed as "flee" (ignoring letter-casing). In this case, the returned JSON will have its results defined as follows:


  "results" : {
    "p1-move" : "Flee",
    "p2-move" : null,
    "p1-result" : "lost",
    "p2-result" : null
   }
        

The rest of the result JSON will be the same structure as other moves.

An example return is given on the below, where the guid provided is fictitious and you will need to provide the one retrieved from the previous startgame request:

Example Request: POST parameters of guid=game_12345abc, pid=player_cfe67890, and movename=thunderbolt

Example Output:



       {
         "guid" : "game_12345abc",
         "pid" : "player_cfe67890",
         "results" : {
           "p1-move" : "Thunderbolt",
           "p2-move" : "Transform",
           "p1-result" : "hit",
           "p2-result" : "missed"
         },
         "p1" : {
            "name" : "Pikachu",
            "shortname" : "pikachu",
            "type" : "electric",
            "weakness" : "ground",
            "hp" : 160,
            "current-hp" : 60,
            "moves" : [
              {
                "name": "Growl",
                "type" : "normal"
              },
              {
                "name": "Quick Attack",
                "dp" : 40,
                "type" : "normal"
              },
              {
                "name": "Thunderbolt",
                "dp" : 90,
                "type" : "electric"
              }
            ],
            "buffs" : [],
            "debuffs" : []
          },
          "p2" : {
            "name" : "Ditto",
            "shortname" : "ditto",
            "type" : "normal",
            "weakness" : "fighting",
            "hp" : 206,
            "current-hp" : 20,
            "moves" : [
              {
                "name": "Transform",
                "dp" : 40,
                "type" : "normal"
              }
            ],
            "buffs" : [],
            "debuffs" : ["attack", "attack"]
          }
        }