Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Plugin for giuseppe that adds @Version route modificator (to allow certain routes for certain api versions)

License

Notifications You must be signed in to change notification settings

smartive/giuseppe-version-plugin

Repository files navigation

giuseppe-version-plugin

This is a plugin for giuseppe. This plugin adds a @Version route modificator to add versioning to an api.

Build Status Build Status Coverage Status semantic-release npm Greenkeeper badge

Installation

To install this package, simply run

npm i giuseppe-version-plugin -S

How to use

Here is a brief example of how to add the plugin to giuseppe:

import { Giuseppe } from 'giuseppe';
import { GiuseppeVersionPlugin } from 'giuseppe-version-plugin';

const app = new Giuseppe();
app.registerPlugin(new GiuseppeVersionPlugin());
app.start();

Versionining

When you want to version your routes, you can use the @Version decorator to do so. It is configurable, which header name should be used and from and until which version the function is valid. When a version header can't be parsed, it defaults to V1 and if no matching version is found, a 404 is returned.

@Controller()
export class VersionedController {
    @Version({ from: 1, until: 1 })
    @Get()
    public functionV1(): string {
        return 'hello from v1';
    }

    @Version({ from: 2, until: 4 })
    @Get()
    public functionV2UntilV4(): string {
        return 'hello from v2 until v4';
    }

    @Version({ from: 5 })
    @Get()
    public functionV5(): string {
        return 'hello from v5 until Infinity.';
    }
}

The default header is Accept-Version.

Changelog

The changelog is generated by semantic release and is located under the release section.

Licence

This software is licenced under the MIT licence.

About

Plugin for giuseppe that adds @Version route modificator (to allow certain routes for certain api versions)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •