Skip to content

rajezvelse/json-server-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON API server with JWT authentication

A light weight, ready to run json rest api for front-end developers who need a quick back-end for prototyping and mocking .

banner

Standalone server

git clone https://github.com/rajezvelse/json-server-jwt.git

cd json-server-jwt

npm install

node server.js

The server will be running in port 3000.

To view the server running, open http://localhost:3000

Demo user : admin / admin

Build and start server using Docker

git clone https://github.com/rajezvelse/json-server-jwt.git

cd json-server-jwt

docker build -f .docker/Dockerfile -t json-jwt:api .

docker run -dti --name="json-api" -p "3000:3000" json-jwt:api

The server will be running in port 3000. To view the server running, open http://localhost:3000 Demo user : admin / admin

Authentication

Request:

curl -XPOST -H "Content-Type: application/json" -d '{"email": "[email protected]", "password": "admin"}' http://localhost:3000/api-token-auth 

Response:

{
    "auth": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTMwMjU5MzE3LCJleHAiOjE1MzAzNDU3MTd9.z_mknTvzY_hl4ulxNSEvn6MqHLrlcyALvsyih1oJGyA",
    "user": {
        "id": 1,
        "username": "admin",
        "password": "admin",
        "email": "[email protected]"
    }
}

Token refresh

Request:

curl -XGET -H "Content-Type: application/json"  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTMwMjU5MzE3LCJleHAiOjE1MzAzNDU3MTd9.z_mknTvzY_hl4ulxNSEvn6MqHLrlcyALvsyih1oJGyA" http://localhost:3000/api-token-refresh 

Response:

{
    "auth": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTMwMjU5ODEzLCJleHAiOjE1MzAzNDYyMTN9.vL_WvjzLDT2rCmIWJJh6lQGSyhPfEFuaqQeG6s31zzY",
    "user": {
        "id": 1,
        "username": "admin",
        "password": "admin",
        "email": "[email protected]"
    }
}

Password reset

Request:

curl -XPOST -H "Content-Type: application/json" -d '{"email": "[email protected]"}' http://localhost:3000/api-password-reset

Response:

{
    "token": "gCYjYn1Fy2VtflPPM9dY"
}

Password reset verify

Request:

curl -XPOST -H "Content-Type: application/json" -d '{"token": "gCYjYn1Fy2VtflPPM9dY"}' http://localhost:3000/api-password-reset-verify

Response:

OK

Password reset confirm

Request:

curl -XPOST -H "Content-Type: application/json" -d '{"token": "gCYjYn1Fy2VtflPPM9dY", "new_password": "admin123"}' http://localhost:3000/api-password-reset-confirm

Response:

Password reset success

Change password

Request:

curl -XPOST -H "Content-Type: application/json"  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTMwMjU5MzE3LCJleHAiOjE1MzAzNDU3MTd9.z_mknTvzY_hl4ulxNSEvn6MqHLrlcyALvsyih1oJGyA" -d '{"password": "admin123", "new_password": "admin"}' http://localhost:3000/users/change-password 

Response:

Password changed

Access routes

Request:

curl -XGET -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTMwMjU5MzE3LCJleHAiOjE1MzAzNDU3MTd9.z_mknTvzY_hl4ulxNSEvn6MqHLrlcyALvsyih1oJGyA" http://localhost:3000/users

Response:

[
  {
    "id": 1,
    "username": "admin",
    "password": "admin",
    "email": "[email protected]"
  }
]

Source

https://github.com/typicode/json-server

About

Light JSON API server with JWT authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors