Backend microservices to support and simplify applications. Simple stateless microservices in Nodejs, with three major functionalities: Authentication with Json web token, JSON Patching and Image Thumbnail Generation.
Project Include Dockerizing app, API tests, Code coverage report, JSdoc, Central Logging system and javascript linting.
- Assignment
- Installation
- Usage
- Test
- Code Coverage Report
- JSdoc
- JS linter
- Dockerize
- Central Log system
- License
[✅] Authentication API
[✅] JSON patching API
[✅] Image Thumbnail Generation API
[✅] Authentication request return a signed JWT which can be used to validate future requests
[✅] If the JWT is missing or invalid, these endpoints should reject the request.
[✅] Patch and thumbnail request must be protected with JWT
[✅] Apply the json patch to the json object, and return the resulting json object.
[✅] Create thumbnail(50x50 pixels) of a public image URL and return the resulting thumbnail
[✅] Include a test suite for the microservices using Mocha.
[✅] Use modern javascript ES6 syntax.
[✅] Use Git for version control, and host the project in a Github repository
[✅] Project should contain documentation with setup and usage instructions.
[✅] Project should install all dependencies with “npm install”, should start the server with “npm start”, and should run the test suite with “npm test”.
[✅] Really, please just don’t use “console.log” as the primary debugging/logging tool.
[✅] Use a javascript linter, along with a linting npm script.
[✅] Dockerize, include a working Dockerfile with the app directory.
[✅] Push a docker image to public DockerHub, and share the link
[✅] 100% code coverage in test suite.
[✅] We recommend using Istanbul to generate code test coverage reports.
[✅] Include JSdoc comments and/or Swagger specifications to impress us.
[✅] Integrate a centralized app logging/monitoring system.
git clone https://github.com/atiqg/hackerbay_microservices.git
cd hackerbay_microservices
npm install
1. Change MY_SECRET and PORT variable in .env
file or use given defaults
MY_SECRET=atiqgauri
PORT=3000
2. Start server with:
npm start
Now use any rest client, curl or if you are using VS Code then use Rest Client Extension to make any of these request:
Second and third request require jwt, get it from first request
POST http://localhost:3000/login
content-type: application/json
{
"username": "atiqgauri",
"password": "hackerbay"
}
###
PATCH http://localhost:3000/patch
Authorization: Bearer <paste_jwt_from_login_request>
content-type: application/json
{
"unPatched": {
"Company": "HackerBay",
"Candidate": "Atiq Gauri",
"Interview Acceptance": "Ongoing"
},
"patch": {
"op": "replace",
"path": "/Interview Acceptance",
"value": "Accepted"
}
}
###
GET http://localhost:3000/thumbnail
content-type: application/json
Authorization: Bearer <paste_jwt_from_login_request>
{
"imageUrl": "https://cdn.jpegmini.com/user/images/slider_puffin_before_mobile.jpg"
}
Test using Mocha and Chai
If server is already running then close it first, then start tests with:
npm test
Run this command to generate html coverage report with Istanbul
npm run coverage
Then we can check coverage report by opening coverage/index.html
file
Run this command to generate JSdoc (require npm JSDoc package globally installed):
npm run docs
Then we can check documentation by opening out/index.html
file
JS linting is done with eslint, run this npm script:
npm run lint
Build a docker image using:
docker build -t username/microservices_api:1.0 .
Run docker image using:
docker run image_id/tag_name
Or you can use my public image at DockerHub
This project doesn't use console.log anywhere, instead it uses winston to generate a central log file,
If you have used the app or tests then log file can be found here:
app.log