npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hapi-hydra

v2.0.0

Published

versioning for hapi, using all three methods: https://www.troyhunt.com/your-api-versioning-is-wrong-which-is/

Downloads

11

Readme

hapi-hydra Build Status

This is a hapi plugin to manage three forms of versioning. It was inspired by Your API versioning is wrong, which is why I decided to do it 3 different wrong ways. This plugin makes it simple to implement all three methods of API versioning described in the article.

  1. URL versioning
  2. custom header
  3. Accept header

The accept header must contain version=<version>, for example: curl -i http://localhost:3000/api/bar -H 'Accept: version=v2'

Plugin version 1.x works for hapi 16.x

Server decorations

The plugin decorates the server with a methods for adding routes.

server.routev([options])

The options are the same as the route configuration object with the following additions:

  • version - the version of the route. [default: 'v1']
  • isDefault - the default version of the route. This route, without version prefix, will invoke the appropriate version of the route. [default: false]

Options

The following plugin options are available:

  • header (string/array) - the custom header(s) to look at in order to choose which endpoint to invoke. Returns version for first match.
  • responseHeader - response header to indicate which version of the route was invoked. [default: 'version']
  • prefix - prefix for the route [default: '/']
  • redirect - whether the plugin should rewrite the url or redirect the user with a 302 to the new endpoint [default: false]

Example

const Hapi = require('hapi');
const Hoek = require('hoek');
const HapiVersion = require('./lib');
const Blipp = require('blipp');

const server = new Hapi.Server();
server.connection({ port: 3000 });

server.register([Blipp, { register: HapiVersion, options: { prefix: '/api', redirect: true } }]);

server.routev({ version: 'v1', isDefault: true, method: 'GET', path: '/', handler: (request, reply) => {

    return reply('foo');
} });

server.routev({ version: 'v1', isDefault: false, method: 'GET', path: '/bar', handler: (request, reply) => {

    return reply('foo');
} });

server.routev({ version: 'v2', isDefault: true, method: 'GET', path: '/bar', handler: (request, reply) => {

    return reply('bar v2');
} });

server.start((err) => {

    Hoek.assert(!err, err);
});

The code above makes the following routes available:

*  GET    /api             # alias of /api/v1
*  GET    /api/bar         # alias of /api/v2/bar
*  GET    /api/v1
*  GET    /api/v1/bar
*  GET    /api/v2/bar