Code Monkey home page Code Monkey logo

nodejs-api-basic's Introduction

nodejs-api-basic

Basic nodejs api

Build/Test/Run

  1. Make sure you have Node version >= 8.9 installed

  2. Run the following from the command line

git clone https://github.com/Jaaromy/nodejs-api-basic.git
cd nodejs-api-basic
npm install
npm test
npm start

Swagger Documentation

After starting the application, the API documentation can be found by visiting the following url in a browser window:

http://localhost:3000/v1/api-docs

Each of the API methods can be tested by clicking on the method to expand it and then pressing Try it out then Execute.

All methods can of course also be called by making a regular REST call to the appropriate endpoint.

Architecture Overview

Server

Node.js

Express

Database

LowDB

Validation

jsonschema

Testing Framework

Jest

Documentation

Swagger

Notes

  1. Types are completely defined in the database as JSON schema (minus the documentation, of course). Only additional properties need to be added to the database as they are then merged with the base properties during validation.

Assumptions

  1. Assumed that when new unit types are created, documentation will be updated to reflect the changes (by modifying the swagger.json file).

Simplifications

  1. While the documentation and endpoints were created for User and Type CRUD operations, they were not implemented and will return a 501 - Not Implemented response code.

  2. Update and Delete operations were not implemented for Unit.

  3. Security was ignored for purposes of the demo. Anyone can hit the endpoints and the app will automatically assume you are user id "1".

  4. While there are basic unit/integration tests, there is not 100% code coverage.

Next Steps

  1. LowDB was used for this demo, but the solution is architected in such a way that a new database can be swapped in simply by creating a new "connector" file and referencing it in db.js. A more robust and scalable database (such as DynamoDB or MongoDB) would be an easy drop in.

  2. Security and Authorization need to be implemented.

  3. Full unit test coverage.

  4. A framework such as pm2 or forever should be used so that the application automatically restarts if there are issues.

  5. Setting up CI/CD and deploying to a cloud service.

nodejs-api-basic's People

Watchers

 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.