Skip to content

Express.js app with microservices: Authentication with JWT, JSON Patching and Image Thumbnail Generation. Project Include Dockerizing app, API tests, Code coverage report, JSdoc, Central Logging system and javascript linting

License

Notifications You must be signed in to change notification settings

atiqg/hackerbay_microservices

Repository files navigation

microservices_api

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.

Table of Contents



Assignments:

[✅] 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

Bonus:

[✅] 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.


Installation:

git clone https://github.com/atiqg/hackerbay_microservices.git
cd hackerbay_microservices
npm install

Usage:

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:

Test using Mocha and Chai
If server is already running then close it first, then start tests with:

npm test

Code Coverage Report:

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


JSdoc:

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


Javascript linter:

JS linting is done with eslint, run this npm script:

npm run lint

Dockerize:

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


Central Log system:

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


LICENSE:

MIT

About

Express.js app with microservices: Authentication with JWT, JSON Patching and Image Thumbnail Generation. Project Include Dockerizing app, API tests, Code coverage report, JSdoc, Central Logging system and javascript linting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages