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

restify-simple-versioning

v1.0.0

Published

Easily add version support to your Restify APIs.

Downloads

265

Readme

restify-simple-versioning

Easily add version support to your Restify APIs.

This Restify middleware adds API versioning via your URIs. The version format is the letter "v" followed by a number (e.g. v1) and is prepended to your route (api/test -> v1/api/test). If no version is added to the URI, the latest version will be used by default. Additionally, the header API-Version is included in each response.

Note, this module was tested on Restify 6.3.2.

Usage

npm i restify-simple-versioning

No need to edit your routes. Simply add the pre-route addVersionRoute and API versioning will be supported automatically (see example). You can then require restify-simple-versioning in any additional file and use the static variables to determine the requested version.

Example

let restify = require("restify"),
    versioner = require("restify-simple-versioning"),
    server = restify.createServer();

versioner.versions = [1, 2]; // If not set, version 1 will be added by default.

server.pre(versioner.addVersionRoute);

server.get("api/test", (req, res, next) => {
  if (versioner.currentVersion === 1) {
    res.send(200, "Version 1");
  } else {
    res.send(200, "Other versions");
  }
  next();
});

The above logic will add support for the following example routes:

https://www.site.com/v1/api/test

versioner.currentVersion = 1
versioner.uri = "v1"
https://www.site.com/v2/api/test

versioner.currentVersion = 2
versioner.uri = "v2"
https://www.site.com/api/test

versioner.currentVersion = 2
versioner.uri = ""

Documentation

versions : Array<Number>

Gets/sets the available API versions. Defaults to [1] if not set.


currentVersion : Number

Gets the current API version.


uri : String

Gets the API version as seen in the URI. If no version is used in the URI, an empty string is returned.


addVersionRoute : Function

Adds version path support to your URI. The version format is the letter "v" followed by a number (e.g. v1). If no version is added to the URI, the latest version will be used by default. Additionally, the header API-Version is included in each response. Throws an InvalidVersionError (status 409) if the version you requested does not exist -- use the VersionNotAllowed event-listener to catch.

License

Copyright (c) 2017 Leandro Silva (http://grafluxe.com)

Released under the MIT License.

See LICENSE.md for entire terms.