There are various ways to version your APIs. One of the most common is to include a version indication in your endpoint path. Something like api/v1/posts.
Another common mechanism is to include the version in your header request.
This site has more details.
Thanks for your reply. Can you please explain . Suppose i have v1/posts in version when should i have to copy v1/posts code in v2/posts and make a new end point for my changes in v1/posts
That depends, which is a frustrating answer I know. Who is reliant on your API? How are you documenting and communicating changes in behavior to the API consumers? Asking the right questions is the first step.
Thanks for your response. i'll try my best to explain the problem. actually we are developing a website something like a food social network. mobile version of this website use api from web server . we changed some features in api and also updated the mobile app for them. Now the users of old mobile app version have issues with new api because they did not updated their app to newer version.for this problem solution we copy the old code in a new route and add a version number something like v2/posts. in this way the old v1/posts also work. i want to ask is this the correct way to do so ? or we have to do something else instead of coping code.
That’s a potential solution. However, if it’s a matter of a single application talking to a single API it may make more sense to force everyone to update the mobile app. That gets into complicated maintenance and operations consideration.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.