I am trying to refactor some older APIs, by changing response codes. But the client which is calling these APIs is using these response codes in their logic. So how to change response codes of APIs without breaking the client, and without API versioning?
I know that we can version APIs, but for that we have to communicate to clients so that they can change their code accordingly. So is there a generic way to do this?
One way is to make the client tell you what version of the API it is coded to, and have the server adapt accordingly.
Back-compatibility can be handled: if the client does not include the 'version indicator' in its request (as existing clients will not be doing) then that means the oldest version.
You're then going to have to have (at least) two sets of response codes, the ones in use today and the ones you want to move to. That's the price of compatibility.
Depending on your user base, you can deprecate and eventually eliminate the older API. Typically that is an announcement that 'the older API will be removed in version x.y'.