A simple stateless microservice in Nodejs, Built with Node.js, Express and Mocha

Overview

Stateless Microservice App

This is a simple stateless microservice in Nodejs, Built with Node.js, Express and Mocha, having three major functionalities -

  • Authentication
  • JSON patching
  • Image Thumbnail Generation

Setup

The API requires Node.js

To get up and running:

1. Clone the repo.

git clone https://github.com/johnchristotle/stateless-microservice-app.git

2. cd into repo. Use your own directory name eg cd my-directory-name OR Use the same directory name(below) if you do not change it.

cd stateless-microservice-app

3. Setup the application by installing its dependencies located at the package.json file with

npm install

4. NOTE: The app gets up and running on port 3000 with npm start.

5. Very Important! Create a .env file and set jwtSecret to any secret phrase you want.

Testing the API routes.

This is an API with post and patch requests, so we will be testing with Postman

Function 1. Authentication

This is a mock authentication so you can pass in any username or password to login.

  1. Set the request to POST and the url to /api/users/login.
  2. In the Body for the Postman request, select x-www-form-urlencoded.
  3. You will be setting 2 keys (for username and password). Set the username key to any name. Set password to any password (minimum of 6 characters).
  4. Hit Send. You will get a result in this format:
{
   "user": "christotle",
   "authorized": true,
   "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Im1vaSIsImlhdCI6MTUzMjAwNDkwMSwiZXhwIjoxNTMyMDI2NTAxfQ.sonItbpZ_yKsRLDXNfDqwN6yN5VbdMVDhgKAMxDmPFY"
}

Function 2. JSON patching

Apply json patch to a json object, and return the resulting json object.

  1. Set the request to PATCH and the url to /api/patch-object.
  2. Set the key jsonObject to an object you would like to patch. Set the key jsonPatchObject to the object you want to use to patch the jsonObject.
Examples:
jsonObject
{ "user": { "firstName": "Rose", "lastName": "Leonard" } }

jsonPatchObject
[{"op": "replace", "path": "/user/firstName", "value": "Christotle"}, {"op": "replace", "path": "/user/lastName", "value": "Agholor"}]
  1. Since this is a secure route, for testing, you will also have to set the token in the Header. Set key as token and value as token you received from Authentication.
  2. Expected result should be:
{ "user": { "firstName": "Christotle", "lastName": "Agholor" } }

FUnction 3. Image Thumbnail Generation

This request contains a public image URL. It downloads the image, resizes to 50x50 pixels, and returns the resulting thumbnail.

  1. Set the request to POST and the url to /api/create-thumbnail.
  2. Set the key imageUrl to a public image url.
  3. Since this is a secure route, for testing, you will have to set the token in the Header. Set key as token and value as token you received from Authentication.
  4. Image will be downloaded and converted to a thumbnail of size 50x50 pixels with a sample result as below:
{
   "converted": true,
   "user": "christotle",
   "success": "Image has been resized",
   "thumbnail": "./public/images/resized/"
}

Unit Testing

Unit testing is done using mochai.

Run npm test from the application's root directory.

Logging

All logs are saved in hackerbay.log in the application's root.

Built With

Known Issues

  1. Test for thumbnail generation with Mocha 'it should accept a public image url and return a resized image' returns a promise which is currently not being handled properly.
  2. Dockerfile has not been fully tested.
  3. Istanbul coverage not working as expected...
You might also like...

A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

"To-do list" is a tool that helps to organize daily activites. It simply lists the things which are needed to be done and allows user to mark them as complete. In this step of project, the CRUD (create, update, delete) methods are implemented. This simple web page is built using webpack and served by a webpack dev server.

Mar 28, 2022

A simple bot for Lingos exercises automation written entirely in Typescript.

A simple bot for Lingos exercises automation written entirely in Typescript.

Linger The spiritual successor to lingus Stack used Typescript SWC Yarn Nodejs Puppeteer Dotenv UUID Nodemon Instalation Prerequisites: Nodejs: ^16.13

May 9, 2022

A simple yet fun wordle discord bot

A simple yet fun wordle discord bot! Invite Link: Wordle Bot

Feb 13, 2022

A simple server application that allows you to perform Wake-on-LAN remotely with a web interface

WoL Helper A simple server application that allows you to perform Wake-on-LAN remotely with a web interface. Usage Install: npm install -g wol-helper

Jul 27, 2022

Simple WhatsApp Bot

Simple WhatsApp Bot

Simple WhatsApp Bot

Jul 8, 2022

Math Magician is a single Page App that allows users to perform simple math calculations

Math Magician is a single Page App that allows users to perform simple math calculations

Math Magician is a single Page App that allows users to perform simple math calculations

Apr 9, 2022

🐡 A simple open source phishing platform for red teams

🐡 A simple open source phishing platform for red teams

Apr 14, 2022

Drag and drop library for two-dimensional, resizable and responsive lists

GridList Drag and drop library for a two-dimensional resizable and responsive list of items Demo: http://hootsuite.github.io/grid/ The GridList librar

Dec 14, 2022

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

JavaScript Algorithms and Data Structures This repository contains JavaScript based examples of many popular algorithms and data structures. Each algo

Dec 31, 2022
Owner
Christotle Agholor
Full-Stack Developer, Blockchain Engineer, Specializes in React, cloud, cross-platform, MERN Stack and full-stack blockchain application development
Christotle Agholor
NodeJS application to upload an image to a S3 Bucket on AWS.

node-upload-image-to-s3-bucket NodeJS application to upload an image to a S3 Bucket on AWS. How it works: You must make a POST request to /upload-imag

Rafael Silva de Lima 6 Sep 28, 2022
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.

List.js Perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on

Jonny Strömberg 10.9k Jan 1, 2023
Math Magicians - A calculator and three subpages built with React + SASS

Math Magicians JavaScript application that contains a calculator and three sub-pages. Built with React + SASS. Built With JavaScript HTML5 SASS React.

Leonardo Albornoz 8 Mar 23, 2022
🤖 EvoBot is a Discord Music Bot built with discord.js & uses Command Handler from discordjs.guide

?? EvoBot is a Discord Music Bot built with discord.js & uses Command Handler from discordjs.guide

Erit Islami 1.4k Jan 8, 2023
Solid.js library adding signaling to built-in non-primitives

This package provides signaled versions of Javascript's built-in objects. Thanks to it, all theirs properties will be automatically tracked while using standard API.

Maciej Kwaśniak 40 Dec 29, 2022
Extensive math expression evaluator library for JavaScript and Node.js

?? Homepage Fcaljs is an extensive math expression evaluator library for JavaScript and Node.js. Using fcal, you can perform basic arithmetic, percent

Santhosh Kumar 93 Dec 19, 2022
BotsApp is an optimized and easy-to-use WhatsApp UserBot written in Node.js

?? BotsApp ?? Your Personal Assisstant, on WhatsApp! BotsApp is an optimized and easy-to-use WhatsApp UserBot written in Node.js. Utilize your persona

BotsApp 5.5k Jan 1, 2023
SiJago - GraphQL Client for Browser and Node.js

SiJago is GraphQL Client for Browser and Node.js, You can write request GraphQL schema using JavaScript Object Style, Why i create this tools, Because for reducing typo when writing GraphQL schema using HTTP client like Axios, Fetch or GraphQL client using Apollo and also to simplify calling the GraphQL schema easy to understand for human.

Restu Wahyu Saputra 7 Mar 13, 2022
📞 NODE.TS - WhatsApp proxy for Discord

?? NODE.TS - WhatsApp proxy for Discord

Bruno Silva 3 Mar 2, 2022
Simple, efficient and powerful discord moderation bot.

Big chungus is a moderation bot with the aim of being efficient and easy to setup. The entire bot can be configured through the website. Features Raid

null 6 Oct 11, 2022