This is a simple JWT Api , where a JWT token is signed and created by hitting the end "/login" endpoint. The JWT token can be verified by hitting the "/verification" endpoint.
Steps to setup:
- First install all the required modules by initialising npm, by using the command
npm init
. - Next, install all the required modules by using the command
npm i
. - The module's which are used in this API are Express, dotenv , jsonwebtoken.
- Next, make a .env file in the root directory of the project, now add a variable named
Secret_token
, and give whatever token you want. - Express is used to setup the server and jsonwebtoken is a package which allows us to deal with JWT, it allows us to create a JWT token as well as verify the token.
- Now start the server by writing
node index.js
in the terminal, this will start the server. - Once the server has started, Open Postman or thunderclient extension on Vs Code, hit the
/login
endpoint by the Post method also specify the body data in JSON Format. - Now hit send, the server will respond with a JSON string which would contain the token, now copy this token.
- Make a new request on Postman or thunderclient, whichever you are using , now hit the
/verification
endpoint - Before making the request, go the the authorization panel and add the token in the bearer section.
- Once the token is added in the bearer section, hit the endpoint.
- The Server will return the data back, which was provided in the
/login
endpoint. - If the token is not valid, an error will be displaced.
Congratulation!!, You have Successfully created as well as verified your own JWT token.