Giter Site home page Giter Site logo

sdammann.webapi.versioning's Introduction

SDammann.WebApi.Versioning

Versioning support for ASP.NET Web Api. Associated blog post: http://damsteen.nl/blog/implementing-versioning-in-asp.net-web-api

There is also a Nuget package available.

Using the library

Put something like this in your Global.asax Application_Start:

// enable API versioning
GlobalConfiguration.Configuration.Services.Replace(typeof (IHttpControllerSelector),
											   new XXXX(GlobalConfiguration.Configuration));

Replace XXX with the name of an IHttpControllerSelector implementation from the SDammann.WebApi.Versioning namespace. The implementations that are included are listed below.

The fully qualified name of the API controllers must include one section that is equal to VersionN, where N is an version number. For example: TestWebsite.Api.Version1.HelloController is an controller with name "Hello" for version 1 of the API. This convention can be changed, see below.

Changing the API controller convention

It is possible to override the default convention used for detecting a Controller's version. This convention can be changed by assigning a different value to the VersionedControllerSelector.VersionPrefix property (new since 1.2).

Make sure to do this very early in your application, for example in the Application_Start method in Global.asax.

IHttpControllerSelector implementations

SDammann.WebApi.Versioning.RouteVersionedControllerSelector: Supports selecting an API controller by the "version" string in the request URI. Requires the routing table to be modified to include an "version" key. You can use something like this:

routes.MapHttpRoute(
				name: "DefaultApi",
				routeTemplate: "api/v{version}/{controller}/{id}",
				defaults: new {id = RouteParameter.Optional}
	);

SDammann.WebApi.Versioning.VersionHeaderVersionedControllerSelector: Supports selecting an API controller by the "X-Api-Version" HTTP header. The integer value of the HTTP header determines the API version to use.

SDammann.WebApi.Versioning.AcceptHeaderVersionedControllerSelectorBase: This in an abstract class that supports versioning by the "Accept" HTTP header and enables callers to use an Accept header value like 'application/vnd.company.myapp-v3+json' to select the API version. Some REST-evangelists think this is the best way to implement API versioning. Derived classes need to implement one method to return the API version from the media type string in the Accept header: GetVersion

SDammann.WebApi.Versioning.AcceptHeaderControllerSelector: Implementation of the AcceptHeaderVersionedControllerSelector class. Requires the Accept header to be in the format of '; version='. For example: 'application/json; version=1'.

License

Apache 2.0 license. License details are available in the LICENSE file.

sdammann.webapi.versioning's People

Contributors

sebazzz avatar goalie7960 avatar davidsavagejr avatar razorsmith avatar

Watchers

Aaron Lewis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.