Giter Site home page Giter Site logo

hb_backend_node's Introduction

HB Back-End

This is a simple stateless microservice in Nodejs, with three major features -

  • Authentication; this returns a signed JWT
  • JSON Patch; this applies a patch to a JSON document and returns it
  • Image Resize (Thumbnail); this resizes an image to 50x50 pixels and returns it

Usage

To run this project follow these steps:

Run npm i or yarn to install all the dependencies

Then run npm start to start the project

Additionally, you can run npm test to run the tests included in the project.

NOTE: Your server has to be running for the integration tests to complete. Also, it is recommended to have an internet connection when running the test.image_thumbnail.js integration test in order to enable it download the image for resize.

Docker

The public image for this project on Docker Hub is at https://hub.docker.com/r/aikaykalz/hb-backend/ To pull the repository,

$ docker pull mosadebayo/hb_node_app

You can run the image for your terminal using the following command

$ docker run --rm -p 3000:3000 mosadebayo/hb_node_app

NOTE: If you encounter permission errors, you should consider running the command with sudo.

Routes

This project has just three routes (one public route and two protected routes) and are as follows:

  • POST http://localhost:3000/login for the login function. This also signs a JSON Web Token for use in the other two routes. Example Request body:
        {
            username: 'username',
            password: 'password'
        }
  • PATCH http://localhost:3000/apply-patch for the JSON Patch function. This applies performs the patch operaion with the data provided in the object. Example Request body:
        { 
            jsonObj: {
                "name": "Adebayo",
                "location": "Lagos"
            }, 
            patchObj: {
                "op": "replace",
                "path": "/name",
                "value": "Adeola"
            }
        }
  • GET http://localhost:3000/gen-thumbnail for the image thumbnail function. This downloads a public image, resizes it (to 50x50 pixels) and returns the resultant image Example Request URL:
    http://localhost:3000/gen-thumbnail?image=https://www.openuped.eu/images/badge/icons/anywhere-online.png

NOTE: Depending on your configuration, you may need to change the host and/or the port number in the URL. For the Patch and Thumbnail URLs, you need to add a header value containing the token. Example:

{
    token: 'your_token_returned_from_the_login_request'
}

Monitor

This application uses node-js dashboard for monitoring. To start the monitor, type the following in your terminal

$ npm run dev

hb_backend_node's People

Watchers

Moses Adebayo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.