DV2017 / lectures-api

A fully tested (in postman) Laravel 5.7 API with simple authentication without passport

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lectures

Laravel 5.7 API WITH AUTHENTICATION

This application makes use of simple authentication and authorization without Passport. The application can be tested with Postman.

Steps to making this application work:

  • 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

Testing in Postman

  • POST: 127.0.0.1:8000/api/register
  • Headers:- Content-Type: application/json
    Body (choose option 'form-data'):-
    name: John Doe
    email: j.doe@example.com,
    password: password,
    password_confirmation: password
  • POST: 127.0.0.1:8000/api/login
  • Headers:- Content-Type: application/json
    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.
  • 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.)
    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.
  • Finally logout using POST: 127.0.0.1:8000/api/logout
  • Headers:- Authorization: Bearer api_token. (Insert the login api_token here.)

That's it.

Based on article https://www.toptal.com/laravel/restful-laravel-api-tutorial. I adapted this tto suit Laravel 5.7.

About

A fully tested (in postman) Laravel 5.7 API with simple authentication without passport


Languages

Language:PHP 96.1%Language:HTML 3.2%Language:Vue 0.6%