REST endpoint that returns the next available integer.
problem statement: https://gist.github.com/ankitwww/a519ebfd040bc171554ea2e9c0cfbe3e
- An operating System(Linux/Macos/Windows)
- NodeJS Installed
- Curl/Postman Installed
- Any mordern browser
- Install NodeJS
- run
npm install
to install packages - run
npm start
to start server, default port is3000
- Install CURL
/user/signup
/user/login
/v1/current
/v1/next
/v1/reset
Replace hostname with http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com for demo(port 80)
Replace http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com with http://localhost:3000 for development
curl --location --request POST 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/user/signup/' --header 'Content-Type: application/json' --data-raw '{ "email":"mail@domain.com", "password":"something" }'
curl --location --request POST 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/user/login' --header 'Content-Type: application/json' --data-raw '{ "email":"mail@domain.com", "password":"something" }'
will return :
{ "message": "Auth Successful!!", "token": "XXXXXX" }
use this token to send in header to get current/next integer and reset integer.
curl 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/v1/current --header 'Authorization: Bearer XXXXX'
curl 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/v1/next' --header 'Authorization: Bearer XXXXX'
With content type: Content-Type: application/x-www-form-urlencoded. (here 10 is the desired value)
curl --location --request PUT 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/v1/current' --header 'Authorization: Bearer XXXXX' --data 'current=10'
Or by passing it as a parameter. (here 10 is the desired value)
curl 'http://ec2-13-234-59-145.ap-south-1.compute.amazonaws.com/v1/reset/10' --header 'Authorization: Bearer XXXXX'