Description: A simple stateless microservice in node with Authentication, JSON patching and Image Thumbnail generation.
kindly follow the step below to run this project locally on your machine for development and testing processes.
clone the repo or use the download option
git clone https://github.com/augustinebest/hackerbay-nodeAPI.git
navigate to the root directory of the project and run
npm install
create a .env file and add
AuthSecret = "<your desired secret key>"
run
npm test
run
npm start
- 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"
}
- 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"
}
}
- HTTP Request method: GET
- ENDPOINT: localhost:8000/api/generateThumbnail?imageUrl=imagePath
- example of imagePath: https://images.unsplash.com/photo-1558981001-792f6c0d5068?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80 Note: this endpoint accepts a query as shown
- Example
'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
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
- 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.
- Augustine Igwe - augustinebest