{"_id":"@adam-26/hapi-api-version","_rev":"8-0f7ca693c80cf6c5d4e537d2e454a951","name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","dist-tags":{"latest":"1.1.2"},"versions":{"1.0.0":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.0.0","gitHead":"5f839a8473003da1cf46e8f5a3040b7a9cb74bd8","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.0.0","_shasum":"aea9d472897fe0031aa01b405b33376f7ae28c35","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"aea9d472897fe0031aa01b405b33376f7ae28c35","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.0.0.tgz","integrity":"sha512-LtuyrEwtIlx51hDbeNO73HtwfJqOyoyBPBBzEn57i+e9t0Ip53jK5MNwyAj1NJmnHypHAVHiX1EF0rv6snyb5Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE+eLNIQPwNQUZ8btNP1jFq49fxt9Odt1DjoKjJr613fAiBiglccpTDl07xSPrTswo1YjTnqOl/e8EtPyRR9z6rqcA=="}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.0.0.tgz_1464893826118_0.855932637816295"}},"1.0.1":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.0.1","gitHead":"d942062ce6905eb2fc34da69cde72c65b6aa7c61","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.0.1","_shasum":"40e0067ca570a8c18357e88bd50240914f205858","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"40e0067ca570a8c18357e88bd50240914f205858","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.0.1.tgz","integrity":"sha512-2c3aOcZmhGbeIaU7BWJQrgBksjzYhtuDieGrdxxlVCetkegY3nrJLNcdRVWtDz6lwUAzOZKY75aBAptn6VrLXA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD8oi2ReGA6+TTCLzbjf+CKGvnLECpDfdugsBbLUNJkuwIhANjOE9Gm+s1vfmkyYDrcEcKILh8wr4gte9Yyi2oohcUE"}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.0.1.tgz_1464896627201_0.7239252687431872"}},"1.0.2":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.0.2","gitHead":"8ea90e5333c4ac3bef97e90bf6ee3ad374e7b53e","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.0.2","_shasum":"d5fb6c7b74a004bba927d3862f7ba06eb1a11717","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"d5fb6c7b74a004bba927d3862f7ba06eb1a11717","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.0.2.tgz","integrity":"sha512-vn5nm9cTcS7BY2fLWZY1lQo9MSsHcO1zfblDDKR8fK1dfvpg9Bpq8wMELWmPxr/hnBf8toXHpFzxtd2It2uEIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMG1R/bcrx9gov3vGFB+qdf6+QnqPVcny6KSgvuuu46AIgdxK/OVoesXBQqxFMRyCyyhRiTYzkGlVej5nH5liZknE="}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.0.2.tgz_1464908085114_0.18484538071788847"}},"1.1.0":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.1.0","gitHead":"674c19636a22b936c635a2945a15122b4ac9b1d0","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.1.0","_shasum":"6ead999b6c15cb180bcda5f18f0b338017bd8fca","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"6ead999b6c15cb180bcda5f18f0b338017bd8fca","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.1.0.tgz","integrity":"sha512-LAyPSQtIX/Jj9Iri5LSvy/JViHjcT5S4K5fzqqCA/yZ0VOqkGZ6UQQ6Mo5TPwvOdmQBvrID24bCR6tEfDevg9Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGzdIjsLLU2fwT9uUpd1iuZo+YpaGaGOhJ03aXBO7jDqAiB63lTn1hsdymwCDCeQAmSthT7ITM9AW882+8ylyobBZg=="}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.1.0.tgz_1464909559108_0.10301900748163462"}},"1.1.1":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.1.1","gitHead":"adab8f32b988fc86be48fc0cfe54e053ffc9975d","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.1.1","_shasum":"a23626fab0b063b1c0eed92732da4b4d55403cdf","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"a23626fab0b063b1c0eed92732da4b4d55403cdf","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.1.1.tgz","integrity":"sha512-TIDn65cTtWdDLUYeixa5qsY7PVTLdf1Lhyg3n6Ln3Y4CEL0x/0L0z1ErzlJwPI2LquoDtCt7Ptg4uiZJ1ZlHdA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICUKpps2gNlKGfGO6gY4+rDINCngcD6xnoqypR6bvbJ9AiBtlXsiuFGmFvdz7NQ0s7fQ5kX+rypq2KS3xHrUzAXNSQ=="}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.1.1.tgz_1464910016313_0.47490565455518663"}},"1.1.2":{"name":"@adam-26/hapi-api-version","description":"An API versioning plugin for hapi.","main":"index.js","scripts":{"test":"lab -a code -t 100 -L -v","test-coverage":"lab -c -a code -r html -o coverage/coverage.html","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"keywords":["hapi","hapijs","api","versioning"],"author":{"name":"Patrick Meier"},"license":"Apache-2.0","engines":{"node":">=4.0.0"},"peerDependencies":{"hapi":">=10.x.x"},"devDependencies":{"code":"^2.0.1","hapi":"^13.4.0","lab":"^10.5.1","semantic-release":"^4.3.5"},"dependencies":{"boom":"^3.1.1","hoek":"^4.0.0","joi":"^8.1.0","media-type":"^0.3.0"},"version":"1.1.2","gitHead":"bdb7c9f96dbe4be2b1bfb94364faca491596aa55","bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","_id":"@adam-26/hapi-api-version@1.1.2","_shasum":"884340da845efce26546022eb3699d2ffafb9260","_from":".","_npmVersion":"2.15.6","_nodeVersion":"4.0.0","_npmUser":{"name":"adam-26","email":"adam-26@outlook.com"},"dist":{"shasum":"884340da845efce26546022eb3699d2ffafb9260","tarball":"https://registry.npmjs.org/@adam-26/hapi-api-version/-/hapi-api-version-1.1.2.tgz","integrity":"sha512-Dt30LG0o/n8VFRkmP9tD2MZChDfjcFpfH37FGgZbA6VQK2eenCcp/WMI4QYPg/tANfVUSt4Gi9cL/bxAuIz76g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDbY9itBmDkHeP+1yPsC4n3rkjWJrH5j8w1o+bHkS8hewIhANxYysiukUGGJ5Oa25d8JYFzT6AMav2H29aLNGDdCUq+"}]},"maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/hapi-api-version-1.1.2.tgz_1464911233910_0.45013015484437346"}}},"readme":"# hapi-api-version\n\n[![Build Status](https://travis-ci.org/adam-26/hapi-api-version.svg?branch=master)](https://travis-ci.org/adam-26/hapi-api-version)\n\nAn API versioning plugin for [hapi](http://hapijs.com/).\n\n*Forked from: https://github.com/p-meier/hapi-api-version*\n\n## Features / Goals\n\n- Supports versioning using mediaTypes defined via `accept` header, as described by the [media type specification](https://tools.ietf.org/html/rfc6838) and used on [github.com](https://developer.github.com/v3/media/)\n- Allows custom function to extract the version number from a request\n- Allows the plugin to be registered multiple times (for example, you could apply the plugin multiple times - each with a custom function to provide multiple options to specify an api version, such as querystring, url path and the default mediaType accept header)\n- 100% test coverage\n- Easy to use and flexible\n- Follows the [hapi coding conventions](http://hapijs.com/styleguide)\n- Allows to follow the DRY principle\n\n## Requirements\n\nRuns with Node >=4 and hapi >=10 which is tested with Travis CI.\n\n## A note about creating media type headers\n\nIf you create a custom media type, be sure to register it with the [iana](http://www.iana.org/form/media-types)\n\n## Installation\n\n```\nnpm install --save @adam-26/hapi-api-version\n```\n\n## Usage\n\nRegister it with the server:\n\n```javascript\nimport * as HapiApiVersionPlugin from '@adam-26/hapi-api-version';\n\nconst Hapi = require('hapi');\n\nconst server = new Hapi.Server();\nserver.connection({\n    port: 3000\n});\n\nconst validVersions = [1, 2];\nconst defaultVersion = 2;\n\nserver.register([{\n    register: HapiApiVersionPlugin,\n    options: {\n        validVersions: validVersions,\n        defaultVersion: defaultVersion,\n        vendorName: 'mysuperapi'\n    }\n}, {\n       register: HapiApiVersionPlugin,\n       options: {\n           validVersions: validVersions,\n           defaultVersion: defaultVersion,\n           descriptor: 'querystring',\n           getVersion: (request, options) => {\n\n           \t\t// Extract the version from the querystring parameter 'version'\n           \t\tif (request.query.version) {\n           \t\t\treturn parseInt(request.query.version);\n           \t\t}\n\n           \t\treturn null;\n           }\n       }\n}], (err) => {\n\n    //Add routes here...\n\n    server.start((err) => {\n        console.log('Server running at:', server.info.uri);\n    });\n});\n\n```\n\nTime to add some routes...\n\nThere are typically two common use cases which this plugin is designed to address.\n\n#### Unversioned routes\n\nThis is the type of routes which never change regardless of the api version. The route definition and the handler stay the same.\nNo `request.plugins['hapi-api-version']` data is available for unversioned routes.\n\n```javascript\nserver.route({\n    method: 'GET',\n    path:'/healthcheck',\n    handler: function (request, reply) {\n\n        return reply({\n          status: 'healthy'\n        });\n    }\n});\n```\n\n#### Versioned routes\n\nThis is the type of routes which actually change.\n\n##### Different route definitions per version\n\nEach route definition is version specific.\n\n```javascript\nconst usersVersion1 = [{\n    name: 'Peter Miller'\n}];\n\nconst usersVersion2 = [{\n    firtname: 'Peter',\n    lastname: 'Miller'\n}];\n\nserver.route({\n    method: 'GET',\n    path: '/v1/users',\n    handler: function (request, reply) {\n\n        return reply(usersVersion1);\n    },\n    config: {\n        response: {\n            schema: Joi.array().items(\n                Joi.object({\n                    name: Joi.string().required()\n                })\n            )\n        }\n    }\n});\n\nserver.route({\n    method: 'GET',\n    path: '/v2/users',\n    handler: function (request, reply) {\n\n        return reply(usersVersion2);\n    },\n    config: {\n        response: {\n            schema: Joi.array().items(\n                Joi.object({\n                    firtname: Joi.string().required(),\n                    lastname: Joi.string().required()\n                })\n            )\n        }\n    }\n\n});\n```\n\nNote the different schemas for response validation here.\n\nThe user still sends a request to `/users` and the plugin rewrites it internally to either `/v1/users` or `/v2/users` based on the requested version.\n\n## Example\n\nA complete working example with routes can be found in the `example` folder.\n\n## Documentation\n\n**hapi-api-version** works internally with rewriting urls. The process is very simple:\n\n1. Check if an `accept` header OR a custom getVersion function is present and extract the version\n2. If a version was extracted check if it is valid, otherwise respond with a status code `415` (The HTTP response code can be configured)\n3. If no version was extracted (e.g. no headers sent) use the default version\n4. Check if a versioned route (like `/v2/users`) exists -> if so rewrite the url from `/users` to `/v2/users`, otherwise do nothing\n\n### Options\n\nThe options for the plugin are validated on plugin registration.\n\n- `validVersions` (required) is an array of integer values. Specifies all valid api versions you support. Anything else will be considered invalid and the plugin responds with a status code as defined by `invalidVersionErrorCode`.\n- `defaultVersion` (required) is an integer that is included in `validVersions`. Defines which version to use if no headers are sent.\n- `vendorName` (required, if no getVersion function defined) is a string. Defines the vendor name used in the `accept` header.\n- `passiveMode` (optional) is a boolean. Allows to bypass when no headers are supplied. Useful when you have serve other content like documentation and reduces overhead on processing those.\n- `basePath` (optional) is a string. In case we have a base path different from `/` (example: `/api/`). Per default this is `/`.\n- `getVersion` (required, if no vendorName defined) is a string. Return an integer to define the requested version, or null/undefined if no version was provided.\n- `descriptor` (optional, required to be unique for multiple plugins) is a string, used to describe the versioning technique. This data is available on the request.plugins['hapi-api-plugin'] object.\n- `invalidVersionErrorCode` (optional) is a integer, used to respond to invalid versions. Defaults to 415.\n\n*NOTE: One of  `vendorName`  or the  `getVersion`  function must be defined*\n\n### Getting the requested API version in the handler\n\n```\nhandler: function (request, reply) {\n\n\tconst pluginData = request.plugins['hapi-api-version'];\n\n\t// the API version\n\tconsole.log(pluginData.apiVersion);\n\n\t// true if the default API version was assigned\n\tconsole.log(pluginData.useDefault);\n\n\t// the number of plugins used to determine the API version\n\tconsole.log(pluginData.count);\n\n\t// 'default' if the default API version was assigned,\n\t// otherwise the descriptor of the plugin used to\n\t// determine the API version\n\tconsole.log(pluginData.descriptor);\n\t// ...\n}\n```\n\nYou can get the API version requested by the user (or maybe the default version if nothing was requested) in the handler. It is stored in `request.plugins['hapi-api-version'].apiVersion`.\n\n### Headers\n\nThe headers must have a specific format to be correctly recognized and processed by the plugin.\n\n##### Accept header\n\n```\naccept: application/vnd.mysuperapi.v2+json\n```\n\nHere `mysuperapi` is what was specified in options as `vendorName`. If the vendor name does not match, the default version will be used instead.\n\n##### Custom getVersion function\n\n```\ngetVersion: (request, options) => { return parseInt(request.query.version, 10); }\n```\n\nFor example, to return a version defined in the querystring.\n\n\n## Running the tests\n\n[lab](https://github.com/hapijs/lab) is used for all tests. Make sure you install it globally before running the tests:\n\n```\nnpm install -g lab\n```\n\nNow just execute the tests:\n\n```\nnpm test\n```\n\nTo see the coverage report in html just execute:\n\n```\nnpm run test-coverage\n```\n\nAfter this the html report can be found in `coverage/coverage.html`.\n\n## License\n\nApache-2.0\n","maintainers":[{"name":"adam-26","email":"adam-26@outlook.com"}],"time":{"modified":"2022-06-12T14:17:20.329Z","created":"2016-06-02T18:57:08.542Z","1.0.0":"2016-06-02T18:57:08.542Z","1.0.1":"2016-06-02T19:43:49.739Z","1.0.2":"2016-06-02T22:54:47.548Z","1.1.0":"2016-06-02T23:19:21.594Z","1.1.1":"2016-06-02T23:26:58.592Z","1.1.2":"2016-06-02T23:47:15.273Z"},"homepage":"https://github.com/adam-26/hapi-api-version#readme","keywords":["hapi","hapijs","api","versioning"],"repository":{"type":"git","url":"git+https://github.com/adam-26/hapi-api-version.git"},"author":{"name":"Patrick Meier"},"bugs":{"url":"https://github.com/adam-26/hapi-api-version/issues"},"license":"Apache-2.0","readmeFilename":"README.md"}