Code Monkey home page Code Monkey logo

express-api-version-manager's Introduction

express-api-version-manager

express-version-api-manager is a node.js module to help you manage api versions with express routes


Installation

npm install express-api-version-manager

Usage

    app.use('/api/:apiVersion', apiVersionManager({
      apiVersionParamName: 'apiVersion',
      versions: {
        v1: {
          router: routerApiV1
        },
        v2: {
          router: routerApiV2
        },
        v3: {
          router: routerApiV3
        }
      }
    }));

Example

const express = require('express');
const apiVersionManager = require('./../index');
const app = express();

const routerApiV1 = express.Router();

const routerApiV2 = express.Router();

const routerApiV3 = express.Router();



app.use('/api/:apiVersion', apiVersionManager({
  apiVersionParamName: 'apiVersion',
  versions: {
    v1: {
      router: routerApiV1
    },
    v2: {
      router: routerApiV2
    },
    v3: {
      router: routerApiV3
    }
  }
}));
//call api/v1/user response -> user1
routerApiV1.get('/user', (req, res) => res.send('user1'));
//call api/v2/user response -> user2
routerApiV2.get('/user', (req, res) => res.send('user2'));
//call api/v3/user response -> user3
routerApiV3.get('/user', (req, res) => res.send('user3'));



//call api/v1/admin response -> admin
//call api/v2/admin response -> admin
//call api/v3/admin response -> admin
//because v2 and v3 inherit from v1
routerApiV1.get('/admin', (req, res) => res.send('admin'));


Contact

GitHub.

express-api-version-manager's People

Contributors

ruslanglaznyov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.