https://github.com/fireisgood/pokemon-location-pokemon
Wrapper around PokeAPI to get Pokemon catchable from a given city or region+route
https://github.com/fireisgood/pokemon-location-pokemon
Last synced: about 1 year ago
JSON representation
Wrapper around PokeAPI to get Pokemon catchable from a given city or region+route
- Host: GitHub
- URL: https://github.com/fireisgood/pokemon-location-pokemon
- Owner: FireIsGood
- Created: 2025-02-24T03:01:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-24T20:52:05.000Z (over 1 year ago)
- Last Synced: 2025-03-08T20:53:13.733Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pokemon Location Pokemon API
Wrapper around the [PokeAPI](https://pokeapi.co) location API to get Pokemon from a city or route in a region.
## API Overview
The API has two separate routes:
- `/city` takes a city name via post request
- `/route` takes a region and route number via post request
### `/city` endpoint
- Get Pokemon from location
- `location` (string): Location name (e.g. `castelia-city`)
- Returns
- `pokemon` (array of strings): All catchable Pokemon in the area.
```json
{
"location": "castelia-city"
}
```
Output:
```json
{
"pokemon": [
"rattata",
"eevee",
"skitty",
"delcatty",
"buneary",
"lopunny",
"pidove",
"audino",
"cottonee",
"whimsicott",
"petilil",
"lilligant",
"zorua"
]
}
```
### `/route` endpoint
- Get Pokemon from region's route
- `region` (string): Region name (e.g. `hoenn`)
- `routeNumber` (int): Route number (e.g. `113`)
- Returns
- `pokemon` (array of strings): All catchable Pokemon in the route
```json
{
"region": "hoenn",
"routeNumber": "113"
}
```
Output:
```json
{
"pokemon": ["sandshrew", "slugma", "skarmory", "spinda"]
}
```
### Errors
Errors are returned as 400 level status codes.
- `400`: You messed up the input data shape
- `404`: You messed up the region name or something else caused the PokeAPI to explode
## Installation
This project uses npm, you can check if it is installed via:
```bash
npm -v
```
After you clone the repo, install the npm packages:
```bash
npm install
```
You can then run the program via the provided npm script:
```bash
npm run dev
```
You should get a response telling you where the server is running:
```shell
$ npm run dev
> dev
> tsx watch src/index.ts
Server is running on http://localhost:4978
```
### Usage
Access the API via post requests to the API endpoints. Here is a simple python example using the
[requests library](https://requests.readthedocs.io/en/latest/):
```py
import requests
endpoint = "city"
data = {"location": "castelia-city"}
r = requests.post(f"http://localhost:4978/{endpoint}", json=data)
if r.status_code == 200:
response = r.json()
print(response)
else:
print("Something went wrong:", r.reason)
endpoint = "route"
data = {"region": "hoenn", "routeNumber": 113}
r = requests.post(f"http://localhost:4978/{endpoint}", json=data)
if r.status_code == 200:
response = r.json()
print(response)
else:
print("Something went wrong:", r.reason)
```
Full Example
```py
import requests
def test_post(endpoint: str, data: dict):
print(f"POST: /{endpoint} and {data}")
r = requests.post(f"http://localhost:4978/{endpoint}", json=data)
if r.status_code == 200:
response = r.json()
print("->", r.status_code, response)
else:
print("->", r.status_code, r.reason)
print("\n== Location endpoints! ==\n")
# Correct call
data = {"location": "castelia-city"}
test_post("city", data)
# Bad call: incorrect data format
data = {"test": "uhh"}
test_post("city", data)
# Bad call: nonexistent location
data = {"location": "testfalse"}
test_post("city", data)
print("\n== Region route endpoints! ==\n")
# Correct call
data = {"region": "kanto", "routeNumber": 1}
test_post("route", data)
# Another Correct call
data = {"region": "hoenn", "routeNumber": 113}
test_post("route", data)
# Bad call: incorrect data format
data = {"test": "uhh"}
test_post("route", data)
# Bad call: nonexistent region
data = {"region": "thisregionisnotreal", "routeNumber": 1}
test_post("route", data)
# Bad call: nonexistent route
data = {"region": "kanto", "routeNumber": 4000}
test_post("route", data)
```
## UML Diagram
Calling the `/city` endpoint.
```mermaid
sequenceDiagram
Client->>+PLP: "/city" {"location": "..."}
PLP->>+PokeAPI: P.getLocationByName(...)
PokeAPI->>-PLP: ['list','of','areas']
PLP->>+PokeAPI: P.getLocationAreaByName(...)
PokeAPI->>-PLP: ['list','of','pokemon']
PLP->>-Client: ['list','of','pokemon']
```
image

Calling the `/route` endpoint.
```mermaid
sequenceDiagram
Client->>+PLP: "/city" {"region": "...", "routeNumber": ...}
PLP->>+PokeAPI: P.getLocationAreaByName(...)
PokeAPI->>-PLP: ['list','of','pokemon']
PLP->>-Client: ['list','of','pokemon']
```
image
