Pokemon Shakespeare
Its a Rest API service to describe a given Pokemon's characteristics in William Shakeperar's words.
The service is written in Go and provides the following endpoint.
GET /pokemon/<pokemon name>
:
- Path Varibles:
- pokemon name :
string
: name of a pokemon
- Response:
200 OK, content-type: application/json, response body as follow
{
name: <pokmon name>
description: <dscription in Shakespeares words>
}
- Example:
➜ http http://192.168.99.104:32300/pokemon/charizard
HTTP/1.1 200 OK
Content-Length: 244
Content-Type: application/json
Date: Sun, 29 Nov 2020 17:36:23 GMT
{
"description": "Charizard flies 'round the sky in search of powerful opponents. 't breathes fire of such most wondrous heat yond 't melts aught. However, 't nev'r turns its fiery breath on any opponent weaker than itself.",
"name": "charizard"
}
Getting Started
Prerequisites
- Install the Go (1.9 >)
- GNU Make
- Docker (optional, but must be installed to build or run the container image)
- curl or http to test the endpoint
Building
Build OSX Binary
make bin/pokemon-darwin-amd64
Build Linux Binary
make bin/pokemon-linux-amd64
Running Locally
- once you build the binary, you can run the program using the following command:
For OSX
./bin/pokemon-darwin-amd64
For Linux
./bin/pokemon-linux-amd64
- if you want to run it as a container,
docker run -d -p 5000:5000 quay.io/hriships/pokemon:0.0.2
Execute HTTP GET to http://localhost:5000/pokemon/pikachu
curl --request GET http://localhost:5000/pokemon/pikachu
{"name":"pikachu","description":"Whenever pikachu cometh across something new, 't blasts 't with a jolt of electricity. If 't be true thee cometh across a blackened berry, 't’s evidence yond this pokémon did misprision the intensity of its charge."}
- Optionally: A API key for funtranslations can be passed from an environment variable
TRANSLATION_API_KEY
to the application
Testing
Run Unit Tests
make unit-tests
Run Integration Test
make integration-test
Implementation Details
- To handler HTTP request it uses gorrila/mux HTTP router for
/pokemon/<name>
endpoint. It simplifies the API testing and extract path variable names.
- Program implements the wrapper on PokeAPI to fetch the normal pokemon’s description. Though Pokeapi does mention the go client library pokeapi-go, however it has somes issue returning the correct response in some case.
- Upon fetching the pokemon description, another wrapper written on funtranslations gets the
pokemon description in Shakespeare's words style.
- Some utility packages are written to mock the HTTP response behaviour
- Used ginkgo and omega for the writing integration tests in BDD style and executing tests result assertions respectively.
Improvements