Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metowolf/koa-router-semver
🍌 Semver Version Router middleware for Koa.
https://github.com/metowolf/koa-router-semver
koa router semver
Last synced: 21 days ago
JSON representation
🍌 Semver Version Router middleware for Koa.
- Host: GitHub
- URL: https://github.com/metowolf/koa-router-semver
- Owner: metowolf
- License: mit
- Created: 2020-08-24T04:00:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T01:34:34.000Z (over 4 years ago)
- Last Synced: 2024-11-19T13:08:05.803Z (3 months ago)
- Topics: koa, router, semver
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [koa-router-semver](https://github.com/metowolf/koa-router-semver)
> Semver Version Router middleware for [Koa](https://github.com/koajs/koa).
* [Semantic Versioning](http://semver.org/) routes
* Multiple version middleware
* Support for Header, search query and path params## Installation
```bash
# npm ..
npm i koa-router-semver
# yarn ..
yarn add koa-router-semver
```## Usage
Server
```js
const Koa = require('koa')
const Router = require('@koa/router')
const SemverRouter = require('koa-router-semver')const app = new Koa()
const router = new Router()
const semver = new SemverRouter()router.get('index', '/', semver.version({
'1.0.0': (ctx) => { ctx.body = 'Hello World!' },
'1.1.0': (ctx) => { ctx.body = 'Hello Koa.js!' }
}))app.use(router.routes())
app.listen(3000)
```Client
```bash
# Specifying a version
$ curl -i -H "Accept-Version: 1.0.0" http://localhost:3000/
HTTP/1.1 200 OK
x-api-version: 1.0.0Hello World!
# Hyphen Ranges version
$ curl -i -H "Accept-Version: >1.0.0" http://localhost:3000/
HTTP/1.1 200 OK
x-api-version: 1.1.0Hello Koa.js!
# Caret Ranges version
$ curl -i -H "Accept-Version: ^1.0" http://localhost:3000/
HTTP/1.1 200 OK
x-api-version: 1.1.0Hello Koa.js!
```## Contributing
Please submit all issues and pull requests to the [metowolf/koa-router-semver](https://github.com/metowolf/koa-router-semver) repository!
## Support
If you have any problem or suggestion please open an issue [here](https://github.com/metowolf/koa-router-semver/issues).
### License
[MIT](LICENSE)