This app provides a list of books in a RESTful API. Source of data obtained from Gramedia by using the web scraping technique.
Apart from providing a booklist API, this app was created primarily to learn how to write unit-testable code in Laravel and also presents use cases of framework features such as:
- Cache Control
- Eloquent
- Error Handling
- Facades
- Form Request Validation
- Sanctum
- Service Providers
- Testing
If you are interested in exploring this app, you can check to start from routes/api.php
, app/
folder & tests/
folder.
In addition to the official documentation from Laravel, here are some reference articles that help the development of this application and may be of interest to you:
- https://ashallendesign.co.uk/blog/how-to-make-your-laravel-app-more-testable
- https://www.larashout.com/creating-custom-facades-in-laravel
- https://timacdonald.me/using-laravels-policies-route-model-binding-without-eloquent/
You can read the API documentation on the following page.
Requirements: PHP 8.1, Composer, RDBMS (such as: MySQL, SQLite, PostgreSQL, etc).
Installation steps:
- Clone this repository
git clone https://github.com/yusuftaufiq/laravel-books-api.git
- Change directory
cd laravel-books-api
- Copy environment file
cp .env.example .env
- Set the database configuration you are using in
.env
- If you don't have SQLite installed, also set the database configuration in the file
.env.testing
- Make sure you have created the database according to the
DB_DATABASE
environment value you set - Install composer dependencies
composer install
- Run the migration using
php artisan migrate
- Run the application using
php artisan serve
Requirements: Docker
Installation steps:
- Clone this repository
git clone https://github.com/yusuftaufiq/laravel-books-api.git
- Change directory
cd laravel-books-api
- Copy environment file
cp .env.example .env
- You may want to change
DOCKER_FORWARD_*
in.env
to prevent port conflicts - Build container with
docker-compose up -d --build site
- Install composer dependencies
docker-compose run --rm composer install
- Run the migration using
docker-compose run --rm artisan migrate
composer cache:clear
: clear app cachecomposer code:analyze
: run static code analyzer using PHP Stan and check code style using PHP Code Snifferphp artisan insights
: analyze code quality using PHP Insightsphp artisan test
: run feature & unit tests
Since this app is currently hosted on Heroku using a free plan, there is no guarantee that this app will be accessible at any time.
- Laravel 9 - Core framework
- PHP 8.1 - Language syntax
- Docker - Container platform
- Github Actions - CI/CD platform
- Greatly inspired by https://github.com/guillaumebriday/laravel-blog
- Thanks to https://github.com/aschmelyun/docker-compose-laravel for the
docker-compose
configuration - Index page created with https://devdojo.com/tails/app
This application is licensed under the MIT license.