A light weight, ready to run json rest api for front-end developers who need a quick back-end for prototyping and mocking .
git clone
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
Request:
curl -XPOST -H "Content-Type: application/json" -d '{"email": "admin@example.com", "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": "admin@example.com"
}
}
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": "admin@example.com"
}
}
Request:
curl -XPOST -H "Content-Type: application/json" -d '{"email": "admin@example.com"}' http://localhost:3000/api-password-reset
Response:
{
"token": "gCYjYn1Fy2VtflPPM9dY"
}
Request:
curl -XPOST -H "Content-Type: application/json" -d '{"token": "gCYjYn1Fy2VtflPPM9dY"}' http://localhost:3000/api-password-reset-verify
Response:
OK
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
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
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": "admin@example.com"
}
]