Sebazzz / SDammann.WebApi.Versioning

Versioning support for ASP.NET Web Api
Apache License 2.0
173 stars 43 forks source link

Use both URL & HTTP Header versioning at the same time #51

Open Jognu opened 9 years ago

Jognu commented 9 years ago

Hi, First, thanks for this great library !

I have a question : is it possible to use versioning with URL for major release, and HTTP Header versioning for minor release ? Exactly like describe here : http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#versioning

Thanks !

Sebazzz commented 9 years ago

Yes, this shouldn't be a problem. Implement IRequestVersionDetector and register it with the library.

The implementation will look a lot like AcceptHeaderRequestVersionDetector except you will also want to look at the route like RouteKeyVersionDetector.

One way (not the most recommended way though for integrating it into the library) to do it which may be enough for your purposes is to implement IRequestVersionDetector. In the GetVersion implementation you call GetVersion of a AcceptHeaderRequestVersionDetector instance and on a RouteKeyVersionDetector instance. You cast the result to SemVerApiVersion then combine them.