Git Product home page Git Product logo

rest-service-boilerplate's Introduction

Build Status Coverage Status

REST Service Boilerplate

A boilerplate project for scalable REST Services using Node.js, Express, Mongoose, PM2, and Swagger

Inspiration

There is usually a lot of redundancy in creating a new RESTful API. You create express routes, and you develop schemas. You come up with a way to validate requests and data going to the database. You then have to document all of this, and that documentation can easily become out-of-sync with the actual implementation. This project seeks to correct all of that duplication of effort by using a Swagger document as the "source of truth". The end result is that an API can be developed with a minimal amount of code or effort.

Features

API Documentation and Test Utility

Start the service, and connect to http://localhost:3000/docs to open Swagger UI. Using Swagger UI, you can:

  • View the generated REST API documentation, including request and response schemas
  • Test your API and see responses

Mapping requests to controllers

In the "paths" section of your swagger.json, use the following format to declare the controller and function to use for each request.

 "x-swagger-router-controller": "person", // this is the controller filename
 "operationId": "GET", // this is the function that the controller exports

See the included swagger.json for a complete example.

Controller Files

server.js initializes the swaggerRouter middleware with controllers directory set as:

{controllers: './api/controllers'}

See [swagger-tools Middleware] (https://github.com/apigee-127/swagger-tools/blob/master/docs/Middleware.md) docs for more info.

Useful Commands

# install modules
npm install

# run tests (mocha, eslint, istanbul)
npm test
npm run lint
npm run coverage

# manage process (these issue common pm2 commands)
npm start
npm stop
npm run reload
npm run status

rest-service-boilerplate's People

Watchers

 avatar  avatar  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.