GithubHelp home page GithubHelp logo

pj-mill / aspnet_webapi2_versioning Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 6.26 MB

Demonstrates 5 techniques for API versioning using route uri, query string parameters, custom request header & accept header (content-type). Requires Fiddler or POSTMAN to test.

C# 99.61% ASP 0.39%

aspnet_webapi2_versioning's Introduction

AspNet_WebApi2_Versioning

An ASP.NET Web Api 2 project that demonstrates several techniques for API versioning using route uri, query string parameters, custom request header & accept header (content-type). The project makes use of custom controller selectors that extend/implement both 'DefaultHttpControllerSelector' and 'IHttpControllerSelector', along with custom attribute-based routing & contraints. Requires Fiddler to test.


####Technique 01

We want to version our web api by defining URIs like the following:

URI Mapped To Controller
/api/v1/tasks/ MyProject.Controllers.V1.TasksController
/api/v2/tasks/ MyProject.Controllers.V2.TasksController

#####To Test

In Visual Studio 2015, uncomment the line '// ConfigureNamespaceVersioning(config);' in the WebApiConfig class, then simply run the project using ctrl-F5, and then in Fiddler, issue the following GET requests ...

GET Requests
http://localhost:[YOUR_PORT_NUMBER]/api/v1/tasks
http://localhost:[YOUR_PORT_NUMBER]/api/v2/tasks

Both will respond with a message confirming which controller the request was routed to. (You may need to change the port number from 50333 to whatever is relevant on your system)


####Technique 02 We want to version our web api by defining URIs like the following:

URI Mapped To Controller
/api/v1/tasks/ MyProject.Controllers.TasksController
/api/v2/tasks/ MyProject.Controllers.TasksV2Controller

#####To Test

In Visual Studio 2015, uncomment the line '// ConfigureControllerNameVersioning(config);' in the WebApiConfig class, then simply run the project using ctrl-F5, and then in Fiddler, issue the following GET requests ...

GET Requests
http://localhost:[YOUR_PORT_NUMBER]/api/v1/tasks
http://localhost:[YOUR_PORT_NUMBER]/api/v2/tasks

####Technique 03#### We want to version our web api by specifying parameters in our URIs like the following:

URI Mapped To Controller
/api/tasks/?V1 MyProject.Controllers.TasksController
/api/tasks/?V2 MyProject.Controllers.TasksV2Controller

#####To Test

In Visual Studio 2015, uncomment the line '// ConfigureQueryStringVersioning(config);' in the WebApiConfig class, then simply run the project using ctrl-F5, and then in Fiddler, issue the following GET requests ...

GET Requests
http://localhost:[YOUR_PORT_NUMBER]/api/tasks/?V1
http://localhost:[YOUR_PORT_NUMBER]/api/tasks/?V2

####Technique 04 We want to version our web api by specifying parameters in our URIs like the following:

URI Header Param Mapped To Controller
/api/tasks/ Version-Num: V1 MyProject.Controllers.TasksController
/api/tasks/ Version-Num: V2 MyProject.Controllers.TasksV2Controller

#####To Test

In Visual Studio 2015, uncomment the line '// ConfigureCustomHeaderVersioning(config);' in the WebApiConfig class, then simply run the project using ctrl-F5, and then in Fiddler, issue the following GET requests ...

GET Requests
http://localhost:[YOUR_PORT_NUMBER]/api/tasks

In the header param sepcify ...

  User-Agent: Fiddler
  Version-Num: V1

OR

  User-Agent: Fiddler
  Version-Num: V2

####Technique 05 We want to version our web api by specifying parameters in our URIs like the following:

URI Content-Type Mapped To Controller
/api/tasks/ application/json MyProject.Controllers.TasksController
/api/tasks/ application/xml MyProject.Controllers.TasksV2Controller

#####To Test

In Visual Studio 2015, uncomment the line '// ConfigureAcceptHeaderVersioning(config);' in the WebApiConfig class, then simply run the project using ctrl-F5, and then in Fiddler, issue the following GET requests ...

GET Requests
http://localhost:[YOUR_PORT_NUMBER]/api/tasks

In the header sepcify ...

  User-Agent: Fiddler
  Content-Type: application/json

OR

  User-Agent: Fiddler
  Content-Type: application/xml

####Resources####

Title Author Publisher
ASP.NET Web API 2 - Building a REST service from start to finish, Second Edition Jamie Kurtz and Brian Wortman APRESS
Building ASP.Net Web API RESTful Service โ€“ Part 10 Taiseer Joudeh Bit Of technology
ASP.NET Web API: Using Namespaces to Version Web APIs Mike.Wasson Microsoft
Demystify Web API Versioning Sachin Kalia C# Corner

aspnet_webapi2_versioning's People

Contributors

pj-mill avatar

Watchers

James Cloos avatar  avatar  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.