The API features the following functionalities -
- Request body contains an arbitrary username/password pair
- Result: Returns a signed Json Web Token (JWT) which is used to validate future requests.
The following two endpoints are protected. The JWT obtained in the “Login” endpoint must be attached to each request. If the JWT is missing or invalid, these endpoints rejects the request.
- Request body contains a JSON object and a Json Patch object.
- Result: Applies the json patch to the json object, and returns the resulting json object.
- Request contain a public image URL.
- Result: Downloads the image, resize to 50x50 pixels, and return the resulting thumbnail.
# Get the latest code from github
git clone https://github.com/balrampariyarath/nodejs-microservice.git
# Go to the project directory
cd nodejs-microservice/
# Install NPM dependencies
npm install
# Start the application
npm start
API available at: http://localhost:3000/api/v1/
# Get the latest code from github
git clone https://github.com/balrampariyarath/nodejs-microservice.git
# Go to the project directory
cd nodejs-microservice/
# Build the docker image
docker build -t <your username>/nodejs-microservice .
# Run the image
docker run -p 49160:3000 -d <your username>/nodejs-microservice
# Docker mapped the 3000 port inside of the container to the port 49160 on your machine
# Get container ID
docker ps
# To see log / app outputs
docker logs <container id>
API available at: http://localhost:49160/api/v1/
Sl.No | Method Name | Method Type | Parameters | URL |
---|---|---|---|---|
1 | login | POST | username (String) and password (Password) | http://localhost:3000/api/v1/login |
2 | validate | POST | token (JWT token) | http://localhost:3000/api/v1/validate |
3 | applyPatch | POST (Content-Type: application/json) | json (json Object), patch (Json Patch Object) and token (JWT token) | http://localhost:3000/api/v1/applyPatch |
4 | getThumbnail | POST | image (Image URL) and token (JWT token) | http://localhost:3000/api/v1/getThumbnail |
- POST Request: http://localhost:3000/api/v1/login
- Content-Type: application/x-www-form-urlencoded
- Params:
username: tester@123
password: testpass - Output Format: JSON
{
"success": "true",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RlckAxMjMiLCJwYXNzd29yZCI6InRlc3RwYXNzIiwiaWF0IjoxNTA2MDE5MjUyfQ.HSMPTV_da14hFqsjMP2aLATmseV76wc0x9YrKEP7_KE"
}
- POST Request: http://localhost:3000/api/v1/validate
- Content-Type: application/x-www-form-urlencoded
- Params:
token: XXX-XXX-XXXXXXXXXXX // token - Output Format: Boolean (true/false)
# If token is valid
true
# Invalid Token
False
- POST Request: http://localhost:3000/api/v1/applyPatch
- Content-Type: application/json
- Params:
{
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImJhbHJhbSIsInBhc3N3b3JkIjoicGFzc3dvcmQiLCJpYXQiOjE1MDU5ODY3Njd9.rSG-BQMLZc8-G3X4hgmlCD6wFA71Tc9CX9TGpS-nuxw",
"patch":[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
],
"json":{
"baz": "qux",
"foo": "bar"
}
}
- Output Format: JSON
{
"success": "true",
"output": {
"baz": "boo",
"hello": ["world"]
}
}
- POST Request: http://localhost:3000/api/v1/getThumbnail
- Content-Type: application/x-www-form-urlencoded
- Params:
image: https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg
token: XXX-XXX-XXXXXXXXXXX // a valid token - Output Format: JSON
{
"success": "true",
"filename": "assets/thumbnails/image-editing-101040_960_720.jpg"
}
Image Source: Google
- Logs are maintained in
logs
directory - All thumbnails are generated into
assets/thumbnails
ditectory
- Unit Tests
- Adding a JS Linter