This API returns a book list to demonstrate how to make good API's
php >= 8.2
composer
docker
To install docker, in case you never used, you can visit the Docker Desktop site and see how to install and configure (WSL) on windows.
./vendor/bin/sail composer install
or
./vendor/bin/sail composer update
./vendor/bin/sail up
You can use the option (-d) to ignore logs and unlock your terminal.
./vendor/bin/sail up -d
./vendor/bin/sail artisan migrate
On the home page you have a form to register new users, and receive the token for using the API in your email.
http://localhost/api_restful/
Now to use this API you need some data. So enter this url in your browser to generate some data (key for JWT and some books for you to get in requests).
http://localhost/api_restful/preparations
You can get all of books, with this endpoint:
http://localhost/api_restful/api/all_books/{limit}
The variable $limit is the max numbers of books that you want.
With this endpoint you can get the book by your id number, by passing $id.
http://localhost/api_restful/api/book/{id}
And now, you can do your's requests on Postman, or your favorite app, but don't forget your token, you should put it on your header requisition, as bellow:
JS
fetch('https://localhost/api/all_books/10', {
method: 'GET',
headers: {
Authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
}
}).then(result => result.text())
Make good use and good luck.
- [Lucas A. R. Volpati] | lucas.volpati@outlook.com - Developer of this API!
- [Rest API] - The best library API