My Laravel Passport REST Api Demo Application

My Laravel Passport REST Api Demo Application

Laravel Passport Api 

This a demo rest api project using Laravel framework.

Laravel Passport provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. Passport is built on top of the League OAuth2 server that is maintained by Andy Millington and Simon Hamp.

User Authentication

MethodRouteDescription
POSThttps://dev.mayeconcept.com.ng/api/loginLogin user
POSThttps://dev.mayeconcept.com.ng/api/registerregister
POSThttps://dev.mayeconcept.com.ng/api/logoutlogout
GEThttps://dev.mayeconcept.com.ng/api/logouttest if you are authenticated
GEThttps://dev.mayeconcept.com.ng/api/userget current  authenticated user
POSThttps://dev.mayeconcept.com.ng/api/userupdate user

Articles

MethodRouteDescription
GEThttps://dev.mayeconcept.com.ng/api/articlesfetch all articles
POSThttps://dev.mayeconcept.com.ng/api/articlescreate new article
GEThttps://dev.mayeconcept.com.ng/api/articles/user/{id}get currently authenticated user single article 
GEThttps://dev.mayeconcept.com.ng/api/articles/{id}get single article
PUT https://dev.mayeconcept.com.ng/ api/articles/{id} update article
DELETE https://dev.mayeconcept.com.ng/api/articles/{id}delete article

Form Data

PropertyData
Loginemail, Password
registername,email,type,password,password_confirmation
articletitle,body,author

Privileges (User Type)

RolePrivilegeName
0view post onlyMember
1create,view,editAdmin
2create,view,edit,deleteSuper Admin

Error Handling and Response type

CodeStatusDescription
200OkThe request was successfully completed
201CreatedA new resource was successfully created
400Bad RequestThe request was invalid
401UnauthorizedInvalid login credentials
403ForbiddenYou do not have enough permission to perform this action
404Not foundThe requested resource/page not found
405Method Not AllowedThe request is not supported by the resource/ method
409ConflictThe request could not be completed due to conflict
500Internal Server ErrorThe request was not completed due to an internal error on the server side
503Service UnavailableThe server was unavailable
Return Type: JSON

Headers

MethodType
Access-Control-Allow-MethodsGET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-HeadersX-Requested-With, Content-Type, XToken-Auth, Authorization

How it works

  1. Register/login via the endpoint 
  2. Upon successful login/registration, copy the token and paste in your header 
  3. update your profile to admin/super admin to update and delete article.

Pictorial Example with Postman 

 

 

test if you are authenticated

 

get all articles

 

get single article
edit article

 

get authenticated user

To get Familiar with the process here is an example implementation method for this API.

 

 

Enjoy this article ? drop a comment below and add your own contribution.

Maye Jacob

Jacob Olorunmaye

Verified Expert
Passionate Backend Developer | Expert in PHP, Laravel, JavaScript, and Golang 🚀 | Crafting seamless, scalable solutions for the digital era

Leave a Reply

Your email address will not be published. Required fields are marked *