I have a spring boot rest API with following endpoints:
myapi/v1/auth
myapi/v1/car
myapi/v1/part
myapi/v1/history
Each of these (except authentication) have 4 controller methods representing GET, POST, PUT, DELETE CRUD operations.
Let's say I have a breaking change that requires modification only for the /car POST endpoint.
To handle the breaking change, I introduce new version for the /car endpoint. I do this by adding a new controller with @RestController annotation mapping to new path:
myapi/v2/car
I'm my opinion, if other endpoints are not affected by this breaking change, they should stay at /v1 endpoint and only /car should get new /v2 endpoint in addition to having its old /v1 endpoint.
As a result, I think my endpoints should now look like:
myapi/v1/auth
myapi/v1/car
myapi/v2/car
myapi/v1/part
myapi/v1/history
My colleague is challenging this and claims that ALL endpoints should get /v2 as well even though they are not affected by the breaking change.
Which one is correct?
There is no black and white answer. The answer is always "it depends". In this case, it depends on how you want to do your API versioning. All of them have advantages and disadvantages. I personally prefer to not use /v1 /v2 stuff at all, but implement a MIME-type that specify which type of /car endpoint they should call. So you are very fine granular by making breaking changes. A brief overview what CAN be done can be found here.