Public
Documentation Settings

Rest API Tutorial

Build REST API with Laravel 8 using JWT Token

In this tutorial we will learn how to Build REST API with Laravel 8 using JWT Token (Json Web Token) from scratch. I’m sure after this topic you will be able to create a Rest API.

POSTRegister New User

https://lvtest.avdemosites.com/api/register
Bodyraw (json)
json
{
    "name": "Joy",
    "email": "joy123@example.com",
    "password": "123456789"
}
Example Request
curl
curl --location 'https://lvtest.avdemosites.com/api/register' \
--data-raw '{
    "name": "Nancy",
    "email": "nancy@example.com",
    "password": "123456789"
}'
200 OK
Example Response
json
{
  "success": true,
  "message": "User created successfully",
  "data": {
    "name": "Nancy",
    "email": "nancy@example.com",
    "updated_at": "2020-09-17T11:46:58.000000Z",
    "created_at": "2020-09-17T11:46:58.000000Z",
    "id": 3
  }
}
Host

lvtest.avdemosites.com

Date

Thu, 17 Sep 2020 11:46:58 GMT

Date

Thu, 17 Sep 2020 11:46:58 GMT

Connection

close

X-Powered-By

PHP/7.4.0

Cache-Control

no-cache, private

Content-Type

application/json

X-RateLimit-Limit

60

X-RateLimit-Remaining

57

Access-Control-Allow-Origin

*

POSTLogin

https://lvtest.avdemosites.com/api/login
Bodyraw (json)
json
{
    "email": "joy@example.com",
    "password": "123456789"
}
Example Request
curl
curl --location 'https://lvtest.avdemosites.com/api/login' \
--data-raw '{
    "email": "nancy@example.com",
    "password": "123456789"
}'
200 OK
Example Response
json
{
  "success": true,
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjE6ODAwMFwvYXBpXC9sb2dpbiIsImlhdCI6MTYwMDM0MzQ2NiwiZXhwIjoxNjAwMzQ3MDY2LCJuYmYiOjE2MDAzNDM0NjYsImp0aSI6ImRMZjlVU0xSMHBZTTdZSGgiLCJzdWIiOjMsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.seklvI3XxfkesfndNhozACHpwmLqdjMpeUzIryeZ20I"
}
Host

lvtest.avdemosites.com

Date

Thu, 17 Sep 2020 11:51:06 GMT

Date

Thu, 17 Sep 2020 11:51:06 GMT

Connection

close

X-Powered-By

PHP/7.4.0

Cache-Control

no-cache, private

Content-Type

application/json

X-RateLimit-Limit

60

X-RateLimit-Remaining

59

Access-Control-Allow-Origin

*

GETLogout

https://lvtest.avdemosites.com/api/logout
Bodyraw (json)
json
{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbHZ0ZXN0LmF2ZGVtb3NpdGVzLmNvbVwvYXBpXC9sb2dpbiIsImlhdCI6MTYwMDY5NTMwMCwiZXhwIjoxNjAwNjk4OTAwLCJuYmYiOjE2MDA2OTUzMDAsImp0aSI6IkRURUtmVGs5aENXSlVLNzkiLCJzdWIiOjIsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.VLhA57j3vuKwEKr4i7kVHNQSbEO094S46uyYFql0mFs"
}
Example Request
curl
curl --location --request GET 'https://lvtest.avdemosites.com/api/logout' \
--data '{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbHZ0ZXN0LmF2ZGVtb3NpdGVzLmNvbVwvYXBpXC9sb2dpbiIsImlhdCI6MTYwMDY5NTMwMCwiZXhwIjoxNjAwNjk4OTAwLCJuYmYiOjE2MDA2OTUzMDAsImp0aSI6IkRURUtmVGs5aENXSlVLNzkiLCJzdWIiOjIsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.VLhA57j3vuKwEKr4i7kVHNQSbEO094S46uyYFql0mFs"
}'
Example Response
No response body
This request doesn't return any response body
No response headers
This request doesn't return any response headers

GETGet User

https://lvtest.avdemosites.com/api/get_user

Get user by token

Bodyraw (json)
json
{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbHZ0ZXN0LmF2ZGVtb3NpdGVzLmNvbVwvYXBpXC9sb2dpbiIsImlhdCI6MTYwMDY5MTA3OCwiZXhwIjoxNjAwNjk0Njc4LCJuYmYiOjE2MDA2OTEwNzgsImp0aSI6Ik5XVm5XdjdjanE2NlJmanIiLCJzdWIiOjIsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.PJbyNcd-s3nG1mnu5z3mjlHM77snLpl05w720k5mZCE"
}
Example Request
curl
curl --location 'https://lvtest.avdemosites.com/api/get_user'
200 OK
Example Response
json
{
  "user": {
    "id": 2,
    "name": "Joy",
    "email": "joy@example.com",
    "email_verified_at": null,
    "created_at": "2020-09-21 12:19:43",
    "updated_at": "2020-09-21 12:19:43",
    "stripe_id": null,
    "card_brand": null,
    "card_last_four": null,
    "trial_ends_at": null
  }
}
Server

nginx-rc

Date

Mon, 21 Sep 2020 12:26:30 GMT

Content-Type

application/json

Transfer-Encoding

chunked

Connection

keep-alive

Vary

Accept-Encoding

Cache-Control

private, must-revalidate

pragma

no-cache

expires

-1

X-RateLimit-Limit

60

X-RateLimit-Remaining

59

X-Frame-Options

SAMEORIGIN

X-XSS-Protection

1; mode=block

X-Content-Type-Options

nosniff

Content-Encoding

br