This laravel application provides an API that displays information about a video game fetched from list of websites
- Fetch project
git clone git@github.com:HazemNoor/game-finder.git
cd game-finder
- Copy file
.env.example
into.env
cp .env.example .env
- Edit file
.env
adding values for these constants
TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=
RAWG_CLIENT_API_KEY=
Get these values from their websites
- You many need to update these values related to
Docker
in.env
SERVER_HTTP_PORT=80
SERVER_HTTPS_PORT=443
USER_ID=1000
GROUP_ID=1000
- Make sure to have
docker-compose
installed on your machine, then execute this command to build docker images
make build
- Run this command to execute
composer install
make up
make install
- Run tests
make up
make test
- If you need to log in to docker container, use these commands
make up
make login
- Stop docker containers
make down
The provided API is
GET http://localhost/api/games
Query Parameter
search=Red Alert 2
Header
Accept: application/vnd.api+json
Example API call via CURL
curl --request GET \
--url 'http://localhost/api/games?search=Red%20Alert%202' \
--header 'Accept: application/vnd.api+json'
Sample successful response body
{
"results": [
{
"name": "Command & Conquer: Red Alert 2",
"image": "https:\/\/media.rawg.io\/media\/games\/673\/67304bfba37b6a18c50a60ab6ba6cebd.jpg"
},
{
"name": "Command & Conquer: Red Alert",
"image": "https:\/\/media.rawg.io\/media\/games\/e87\/e87bbd9feb37b226b1b6a4f11e9492a0.jpg"
}
]
}
- All Clients are registered to
ClientFactory
throughGameFinderProvider
, you can add new clients there
$factory->addClient($client);
- Clients are Consecutively used in the same order they are registered in
ClientFactory
- If a Client fails or doesn't return results we continue to use the next Client, otherwise, we just use result from that Client
- Results are returned in the same order that is returned from Clients
- If any Error happens in any Client, an Exception
ClientRuntimeException
is reported for further analysis later
Testing is divided in two classes HazemNoor\GameFinder\Tests\ApiTest
and HazemNoor\GameFinder\Tests\GameFinderTest
You can run unit test using these commands
make up
make test
The coding style used is PSR-12 and is included with the testing command make test
using PHP_CodeSniffer
- Implement Circuit Breaker Algorithm to prevent failures from constantly recurring after a certain threshold of failures in Clients
- Implement apiDoc for API Documentation
- Add API Authentication