A REST API for retrieving a Pokemon shakespearean description.
An example using curl
$ curl http://localhost:5000/pokemon/charizard
{
"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."
}
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
In order to build, test and run this project the following dependencies need to be fulfilled:
This document also assumes that git
, dotnet
and docker
are part of your PATH
so that they are considered valid commands when entered in a shell.
You can double check that by trying the following commands that should return you an output similar to the below ones.
git --version
# git version 2.24.0.windows.1
dotnet --version
# 3.1.100
docker --version
#Docker version 19.03.4, build 9013bf5
Repository structure.
root
│ README.md
│ PokeShake.sln
│
└───art
│
└───src
│ │
│ └───PokeShake.DTO # Data transportation objects library
│ │
│ └───PokeShake.Services.Common # Common logic to all the services
│ │
│ └───PokeShake.Services.FunTranslations # FunTranslation service impl.
│ │
│ └───PokeShake.Services.PokeApi # PokeApi service impl.
│ │
│ └───PokeShake.Services.PokemonShakespeareanDescription # Shakespearean desc. impl.
│ │
│ └───PokeShake.PokeShake.WebApi # Web Api
│
└───tests
│
└───PokeShake.Tests # Misc test project
│ │
│ └─Integration
│ │
│ └─Unit
│
└───PokeShake.Services.FunTranslations.Tests # FunTranslations tests
│ │
│ └─Integration
│ │
│ └─Unit
│
└───PokeShake.Services.PokeApi.Tests # PokeApi tests
│ │
│ └─Integration
│ │
│ └─Unit
│
└───PokeShake.Services.PokemonShakespeareanDescription.Tests # Shakespearean desc tests
│ │
│ └─Integration
│ │
│ └─Unit
│
└───PokeShake.WebAPi.Tests # Web API tests
│
└─Integration
│
└─Unit
Clone the master branch of this repository into your local system
git clone https://github.com/p1va/pokeshake.git
Move into the newly created directory containing the repository
cd pokeshake
Build a docker image containing the web api app.
For Windows:
docker build -f src\PokeShake.WebApi\Dockerfile -t pokeshakeapi .\.\.
For Unix:
docker build -f src/PokeShake.WebApi/Dockerfile -t pokeshakeapi ././.
Double check the outcome of the command by looking at the list of images.
An image named pokeshakeapi
should be there.
docker image ls
Create and run a container based on the image we just built with the following command
docker run -d -p 5000:80 --name mypoke pokeshakeapi
Double check the outcome of the command by looking at the list of active containers.
A container named mypoke
should be there.
docker container ls
From the list you should also be able to identify the container ID which you can use to view the app logs.
docker logs --follow <container id>
Assuming that the newly created container has 93d060dc0163
as ID, you can view its logs with the following command
docker logs --follow 93d060dc0163
Now that the web api app is running you can try it with the http client of your choice.
In this example i am using curl
curl http://localhost:5000/pokemon/charizard
In addition you can visually test the API by browsing to http://localhost:5000/ where the Swagger UI is located.
Starting at the root directory of the git repository (the one where PokeShake.sln
file is located)
Restore nuget packages with the following command.
dotnet restore
And then run the tests
dotnet test
Note that Web API integration tests use port 9999 so tests could fail if that port is already in use. If this is the case just change the port in the
WebApiIntegrationTests
class
- .NET Core 3.1 - Development framework
- AspNet Core 3.1 - Web framework of choice
- Docker - Containers platform
- Visual Studio 2019 - IDE
- VSCode - IDE
- Best-README-Template - A README template
- Ensure.That - A guard clause library
- FluentAssertions - An extension methods libraries for tests assertions
- FunTranslations API - An API for unusual text translations
- Moq4 - A mocking library for easier testing
- Newtonsoft.Json - A JSON serialization/deserialization library
- PokeAPI - An API for retrieving pokemon info
- Swashbuckle.AspNetCore - A Swagger implementation for AspNet Core
- xUnit - A test framework