Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consistency

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consistency

API versioning plugin for hapi.js

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
69
Maintainers
1
Weekly downloads
 
Created
Source

npm version Build Status

Consistency

A hapi.js plugin for versioning your API. Borne out of this talk: http://www.slideshare.net/shakefon/hapidays-2014

Installation

npm install consistency

Register plugin with your hapi application, provide the option(s) required for version detection.

server.register({
  register: require('consistency'),
  options: {
    uriParam: 'apiVersion',
    acceptNamespace: 'consistencyExample',
    customHeaderKey: 'api-version'
  }
}, function (err) {
  if (err) console.log('Consistency plugin failed to load');

});

or, via Glue and manifest:

var manifest = {
  connections: [...],
  plugins: {
    consistency: {
      uriParam: 'apiVersion',
      acceptNamespace: 'consistencyExample',
      customHeaderKey: 'api-version'
    }
  }
};

Glue.compose(manifest, function (err, server) {
  ...
});

Versionize your Routes

Array of handlers

server.route({
  id: 'array',
  method: 'GET',
  path: '/array',
  handler: {
    versioned: [
      function(request, reply) {
        reply({
          version: '1.0'
        });
      },
      function(request, reply) {
        reply({
          version: '2.0'
        });
      }
    ]
  }
});

Object of handlers

server.route({
    id: 'object',
    method: 'GET',
    path: '/object',
    handler: {
      versioned: {
        'v1.0': function(request, reply) {
          reply({
            version: '1.0'
          });
        },

        'v2.0': function(request, reply) {
          reply({
            version: '2.0'
          });
        },

        'v1.5': function(request, reply) {
          reply({
            version: '1.5'
          });
        }
      }
    }
});

Version Matching

A version can be provided with or without the v prefix and can also be provided using the latest keyword which will use the latest versioned endpoint.

Matching of version handlers is cached to remove redundent checks based on the route method and route path.

If an endpoint has not changed in a specific version of the api, we can omit it and the matcher will use the version that is closest to the one request. for example if in version 2 we didn't update the users endpoint a request would return version 1

If you provide the version in shorthand (v1, 1) it will return greatest version available for that api version. for example given the versions 1, 1.2, 1.5 providing 1 will return 1.5.

Keywords

FAQs

Package last updated on 09 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc