Your task is to create a REST API using Laravel that aggregates game data from an external open API. The API should allow users to search for games, retrieve game details, and manage a list of favorite games. As a bonus, you can secure the application with basic user authentication and enable favorite games functionality only for authenticated users.
- Set up a new Laravel project using Laravel 8 or above.
- Use a SQLite database for this project.
- Register for an API key from an open game database API, such as RAWG (https://rawg.io/apidocs) or IGDB (https://api.igdb.com/).
- Create a Game model with the following attributes: id, game_id, title, summary, release_date, and cover_url.
- Create a migration for the Game model and run the migration to create the games table in the database.
- Create a GameController that handles the following operations:
- Search for games using the external API based on a query string.
- Retrieve game details from the external API and store them in the local database.
- Manage a list of favorite games for authenticated users (optional).
- Create the following API routes for managing games:
- GET /api/games/search?q={query}: Search for games using the external API based on a query string and return the results as JSON.
- GET /api/games/{game_id}: Retrieve game details from the external API based on the game_id, store them in the local database, and return the game details as JSON.
- GET /api/favorites: Retrieve a list of favorite games for the authenticated user as JSON (optional).
- POST /api/favorites: Add a game to the authenticated user's list of favorite games (optional).
- DELETE /api/favorites/{game_id}: Remove a game from the authenticated user's list of favorite games (optional).
- Run
php artisan passport:keys
to deploying passport. - Cache the results of game searches and game details to reduce the number of calls to the external API.
- Implement basic user authentication using Laravel's built-in authentication system, such as Laravel Passport, to secure the API.
- Ensure that only authenticated users can add or remove games from their list of favorite games.
- Implement rate limiting for the API to prevent excessive usage.
- Add the ability to filter game searches by release date, platform, or genre.
- Implement a recommendation system that suggests games based on the authenticated user's list of favorite games.
Please provide a link to a GitHub or Gitlab repository containing your Laravel project. Make sure your repository is public so we can review your code. Include a README file with instructions on how to set up and use the API, as well as any necessary API key registration information.
- Download this repository
composer install
composer update
npm install
- Rename the
.env.example
file to.env
and add the following configurations:DB_CONNECTION=sqlite
DB_DATABASE="C:\\absolute\\path\\to\\game-api\\database\\database.sqlite"
RAWG_API_KEY=YOUR-RAWG-API-KEY
RAWG_API_HTTP="https://api.rawg.io/api"
- Create the file
database.sqlite
in the project-folderdatabase
- Migrate the database and seed with
php artisan migrate --seed
- Run
php artisan passport:keys
to deploying passport. - Create passport client for testing by using
php artisan passport:client --personal
and choose0
when asking[0] users
- Start the webserver with
php artisan serve
and use the webserver url to get access to the api.
It is recommended to use a software like Postman to make api requests.
use POST /api/login
and add following form data:
email : "[email protected]"
password : "password"
The request returns the token, which must be used for future requests.
Use the token to check if the authentification was successful by using:
GET /api/user
with Bearer-Token, you got in the step before.
-
Simply get game from RAWG API and cache the result (works without authentication).
GET /api/games/search?q={query}
-
Get game details by id and save it to database. Use also database entry if exist to save api calls (works without authentication).
GET /api/games/{id}
-
Get games by (multiple) filter
GET /api/user/games/filter?{filter}={value}
- filter: release_date, value: date format YYYY-MM-DD
- filter: platform, value: numeric
- filter: genre, value: numeric
-
Get favorite games from authenticated user.
GET /api/user/games/favorites
-
Add favorite game to authenticated user
POST /api/user/games/favorites?game_id={id}
-
Remove favorite game from authenticated user
DELETE /api/user/games/favorites?game_id={id}
-
Rate favorite game from authenticated user from 0 to 10
PATCH /api/user/games/favorites/rate?game_id={id}&rating={0-10}
-
Remove rating of favorite game from authenticated user (set to default)
PATCH /api/user/games/favorites/rate/remove?game_id={id}
All routes that are not authenticated have a 5 hits per minute rate limiter middleware. To change that, edit the $perMinute
variable in App\Http\Middleware\SearchGameRequestLimiter
and App\Http\Middleware\RetrieveGameDetailsRequestLimiter
.