koa-router-semver

    0.1.0 • Public • Published

    koa-router-semver

    Semver Version Router middleware for Koa.

    • Semantic Versioning routes
    • Multiple version middleware
    • Support for Header, search query and path params

    Installation

    # npm .. 
    npm i koa-router-semver
    # yarn .. 
    yarn add koa-router-semver

    Usage

    Server

    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

    # Specifying a version
    $ curl -i -H "Accept-Version: 1.0.0" http://localhost:3000/
    HTTP/1.1 200 OK
    x-api-version: 1.0.0
    <more headers>
    
    Hello 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.0
    <more headers>
    
    Hello Koa.js!
    
    # Caret Ranges
    $ curl -i -H "Accept-Version: ^1.0" http://localhost:3000/
    HTTP/1.1 200 OK
    x-api-version: 1.1.0
    <more headers>
    
    Hello Koa.js!

    Contributing

    Please submit all issues and pull requests to the metowolf/koa-router-semver repository!

    Support

    If you have any problem or suggestion please open an issue here.

    License

    MIT

    Keywords

    none

    Install

    npm i koa-router-semver

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    5.71 kB

    Total Files

    4

    Last publish

    Collaborators

    • metowolf