A test api performing CRUD operations with laravel(php) framework.
- Laravel - https://laravel.com/docs/5.8/installation
- MAMP or XAMP
- Postman(to test APIs) - https://www.getpostman.com/
- Vscode - https://code.visualstudio.com/ or any editor of your choice
Ensure requirements are meet before you clone or download the project.
Use git clone https://github.com/dagenius007/test-api.git
to clone the project
Navigate to your root folder of your project, in your terminal: run composer update
to install all packages
Create a clone of .env.example
file and rename it to .env
run php artisan key:generate
to generate the application key
Create a database in your phpMyAdmin (you must have setup MAMP or XAMP on your pc)
configure .env
file
DB_HOST=127.0.0.1
DB_PORT=3306 or 8889(if you are running on MAMP)
DB_DATABASE=your-database
DB_USERNAME=your-phpmyadmin-username
DB_PASSWORD=your-phpmyadmin-password
In your terminal: run php artisan migrate
to migrate the database
start your application by running php artisan serve
.
The application should be visible on http://localhost:8000
If all is set then we are ready to test 😄 👍
HTTP Method : GET
Route : http://localhost:8000/api/external-books?name=:query
Parameter : { "name" : query }
HTTP Method : POST
Route : http://localhost:8000/api/v1/books
Parameter & Example Request : { "name": "My first book Book", "isbn": "123-3213243567", "authors": ["John Doe" , "Alli"], "number_of_pages": 350, "publisher": "Acme Books", "country": "Nigeria", "release_date": "2019-01-21" }
HTTP Method : POST
Route : http://localhost:8000/api/v1/books
Parameter & Example Request : ---
HTTP Method : PATCH
Route : http://localhost:8000/api/v1/books/:id
Parameter & Example Request : { "name": "My Last Book", "isbn": "123-3213245655", "authors": ["Josh" , "Boy"], "number_of_pages": 450 }
HTTP Method : DELETE
Route : http://localhost:8000/api/v1/books/:id
Parameter & Example Request : ----
HTTP Method : GET
Route : http://localhost:8000/api/v1/books/:id
Parameter & Example Request : ----
Sqlite database was used for testing .
Install PhpUnit -- https://phpunit.de/getting-started/phpunit-7.html.
run php artisan migrate --database=sqlite
to setup up the database
run comoposer test
to perform test
Test file can be found in test/Unit/BookTest.php