Git Product home page Git Product logo

idylwood-webapi's Introduction

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

Build and start server

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

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

idylwood-webapi's People

Contributors

workcontrolgit avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.