Skip to content

A REST API that, given a Pokemon name, returns its Shakespearean description.

License

Notifications You must be signed in to change notification settings

lucamazzanti/shakespeare-pokemon

Repository files navigation

Shakespeare Pokemon REST API

build status release status coverage maintainability Known Vulnerabilities Microsoft Naming Guidelines Hits license: GPL v3

shakespeare-pokemon-logo

What if the description of each Pokemon were to be written using Shakespeare's style?

This is a REST API that, given a Pokemon name, returns its Shakespearean description.

API Specification

Signature: GET endpoint: /pokemon/<pokemon name>/

Example: http://localhost:5000/pokemon/charizard/

Output:

{
	"name": "charizard",
	"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."
}

How to run

Download the Linux image from Docker Hub and run it:

docker pull lmazzanti/shakespeare-pokemon
docker run -d -p 5000:80 --name shakespeare-pokemon lmazzanti/shakespeare-pokemon

If you have an authentication token from Fun Translations you can pass it as:

docker run -d -p 5000:80 -e "API:Shakespeare:AuthenticationToken=xxxx" --name shakespeare-pokemon shakespeare-pokemon

Go to http://localhost:5000 in a browser to test the app.

landing-page

Go to the Swagger API link to read the examples.

See Docker Hub repository for more details.

See Docker run command form more details on how to run it.

How to build

Here the steps to build and run locally the program.

Prerequisites

Download source code

Download the source manually or clone the Git repository:

git clone https://github.com/lucamazzanti/shakespeare-pokemon

Run the application locally

Navigate to the project folder at \ShakespearePokemon.API.

Run the following command to build and run the app locally:

dotnet run

Go to http://localhost:5000 in a browser to test the app.

Press Ctrl+C at the command prompt to stop the app.

Run in a Linux container

In the Docker client, switch to Linux containers.

Navigate to the project folder at \ShakespearePokemon.API.

Run the following commands to build and run the app in Docker:

docker build -f Dockerfile -t shakespeare-pokemon ..
docker run -it --rm -p 5000:80 --name shakespeare-pokemon shakespeare-pokemon

The build command arguments:

  • Name the image shakespeare-pokemon.
  • Run the Dockerfile working from the parent folder (the double period at the end).

The run command arguments:

  • Allocate a pseudo-TTY
  • Automatically remove the container when it exits.
  • Map port 5000 on the local machine to port 80 in the container.
  • Name the container shakespeare-pokemon.
  • Specify the shakespeare-pokemon image.

If you have an authentication token from Fun Translations you can pass it as:

docker run -it --rm -p 5000:80 -e "API:Shakespeare:AuthenticationToken=xxxx" --name shakespeare-pokemon shakespeare-pokemon

Go to http://localhost:5000 in a browser to test the app.

Project details

This is a case study of a RESTful API made in ASP NET Core.

It consumes 2 external API and produces a new result.

  • The pokemon API asks caching as requirement.
  • The translation API has an heavy rate limiting of 5 calls\hour without an authentication token.

The project structure choosen for that tiny example avoid over splitting into projects:

  • A single Web Api 5.0 project, layers are divided in folders.
  • A single NUnit test project holding all the categories: unit, integration, functional tests.

The project can be run in a linux docker container, hosted on a web server or self-hosted.

The project was developed using the github management lifecycle, see here for tasks and more considerations.

Github actions runs the CI/CD.

External API

About

A REST API that, given a Pokemon name, returns its Shakespearean description.

Resources

License

Stars

Watchers

Forks

Packages

No packages published