augustinebest / hackerbay-nodeAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node API Task - Hackerbay

Description: A simple stateless microservice in node with Authentication, JSON patching and Image Thumbnail generation.

Introduction

kindly follow the step below to run this project locally on your machine for development and testing processes.

Step 1

clone the repo or use the download option

git clone https://github.com/augustinebest/hackerbay-nodeAPI.git

Step 2

navigate to the root directory of the project and run

npm install

Step 3

create a .env file and add

AuthSecret = "<your desired secret key>"

Step 4 - Testing

run

npm test

Step 5 - Start application

run

npm start

API Endpoints

Login authentication

  • HTTP Request method: POST
  • ENDPOINT - localhost:8000/api/login
  • Note - this accepts username and password as requests and return a token which can be used for further authorization request.
  • Example:
Request: {
    username: "Hackerbay",
    password: "1234"
}
Response: {
    "status": true,
    "user": "Hackerbay",
    "token": "Genereated token"
}

JSON Patch

  • HTTP Request method: PATCH
  • ENDPOINT - localhost:8000/api/jsonpatcher
  • Note - the generated token is added as an Authorization in the headers
  • Example
'headers': {
   'Authorization': 'Generated token'
 }
 Request: {
     "document": {
         { "name": "best", "gender": "male" }
     },
     "patch": [{ "op": "replace", "path": "/name", "value": "Augustine" }]
 }
 Response: {
     "status": true,
     "result": {
        "name": "Augustine",
        "gender": "male"
    }
 }

Generated Thumbnail

'headers': {
   'Authorization': 'Generated token'
 }
Request: localhost:8000/api/generateThumbnail?imageUrl=imagePath
Response: returns an image of size 50 x 50

Note: checkout the documentation hosted on postman

Docker

This project was dockerised on docker hub, use the following command to run

docker pull augustinebest/hackerbay-node-api
docker run -p 127.0.0.1:3000:3000 --env secret=randomstring augustinebest/hackerbay-node-api 

Packages used

  • mocha - For automated tests.
  • jsonwebtoken - Token generation and verification.
  • body-parser - Allows incomming requests
  • express - small, robust tooling for HTTP servers
  • sharp - converts large image to smaller images of varying dimensions
  • eslint - a tool for identifying and reporting on patterns
  • should - Expressive assertion library.

Author

About


Languages

Language:JavaScript 95.6%Language:Dockerfile 4.4%