This application makes use of simple authentication and authorization without Passport. The application can be tested with Postman.
- Create database 'lectures' in mysql with phpmyadmin
- In the command line: composer install
- php artisan migrate
- php artisan db:seed
- php artisan serve: at 127.0.0.1:8000
- POST: 127.0.0.1:8000/api/register Headers:- Content-Type: application/json
- POST: 127.0.0.1:8000/api/login Headers:- Content-Type: application/json
- Retrieve data from the database using GET: 127.0.0.1:8000/api/lectures Headers:- Authorization: Bearer api_token. (Insert the login api_token here.)
- Finally logout using POST: 127.0.0.1:8000/api/logout Headers:- Authorization: Bearer api_token. (Insert the login api_token here.)
Body (choose option 'form-data'):-
name: John Doe
email: j.doe@example.com,
password: password,
password_confirmation: password
Body (choose option 'form-data'):-
email: j.doe@example.com,
password: password,
Note: The JSON response gives an api_token. Keep this at hand. This is needed to logout.
This will list all the data in the database table 'lectures'.
If there is an exception, a simple user friendly error message is returned as response.
That's it.
Based on article https://www.toptal.com/laravel/restful-laravel-api-tutorial. I adapted this tto suit Laravel 5.7.