The best way to version a RESTful API is a topic of constant debate and every other approach have their own pros and cons. There is no 'one size fi...
For further actions, you may consider blocking this person and/or reporting abuse
Good post.
Is it possible to use URL path versioning and header API versioning combination? I added URL versioning support to my API but it breaks access to the old URL(api/authors). now I have to specify version in the URL(api/v1.0/authors). but some of the client apps use that old URL. are there any solutions for that?
Yes you could use multiple versioning schemes. Supporting multiple versioning Schemes section in this article has an example on how to implement both the query params versioning scheme and request header versioning scheme.
You can try adding two url paths like
[Route("api/[controller]")]
[Route("api/v{version:apiVersion}/[controller]")]
for your base controller so that it uses both url
And how do you work with changes on db? for example v1 has one table with 5 fields, v2 you split one field into 2 fields, how can you automate the database changes when an user wants to use the new versiΓ³n?
This was an excellent post, thank you so much for taking the time to put this together!
I wanted to say, on the line where it specifies the API version key and value:
demo.org/api/resource?v=1.1
Having it only be "v=1.1" didn't work for me. I actually had to match that to the image provided directly below, with that parameter being "api-version=1.1"
Once I did that, it worked perfectly!
Thank you for spotting this. The one on the screenshot is correct. I'll update the article.
Question about versioning the datamodel
Lets say you have an API that use AutoMapper on a datamodel.
Now, if the datamodel changes, the API will still compile like nothing happend, but the end result wil not be compatible anymore
I see two different ways out of this:
1:
Project
- DTO
- V1
PersonDTO
- V2
PersonDTO
2:
Project
- DTO
PersonDTO_V1
PersonDTO_V2
What would be considered best practice here?
Just figured it out myself by testing
Adding version to the ClassName is best because else having USING statements to support multiple versions in the same API class wil create problems if ClassNames are the same
That is a great post, in your opinion, what are the best approaches for versioning a REST API?
I think it depends on the nature and complexity of the REST API. In the articles, I've laid out the few approaches. For simpler APIs I'd go with either using path param approach or using the request headers.
Thanks for the answer :)
Great post. I am new to this i am wondering how to do you cater for DTO changes when versioning? Do I duplicate them and cut or add fields needed for a particular version or I use one DTO?
Great article!
Thanks so much for this!
This is great. It's so nice to see these options baked in instead of having to roll our own support. Thanks for writing this up!
Thanks for sharing this. Never knew there was a version management library within asp net core
Great post, thank you!
Good post.
Thanks for your good guide. There's a question here. Can we version API data models?