URI path versioning is relatively easy to understand and implement, but if you don't keep previous versions active, replacing your old URIs with new version numbers will break any integrations that use the old version, and clients will need to update their software to work with your API.
APIs only need to be up-versioned when a breaking change is made. Breaking changes include: a change in the format of the response data for one or more calls. a change in the request or response type (i.e. changing an integer to a float)
When exposing different API versions how do you handle storing and retrieving data that might have different structures?
Let's say we have two API versions; V1 and V2. V1 and V2 both have a POST endpoint at 'https://api.com/message' which will create a message in the database based on the passed data like:
{
DOB: '2014-12-01'
}
In V1, the data required is different from V2 because in V2 we decide to change DOB from a string with the format 'YYYY-MM-DD' to an integer timestamp e.g. 1284723728323
In this case when we save data from a call with the V2 API the DOB field will be an integer but when saving from a call to V1 it will be a string in a very different format.
With each iteration of the API we might modify many aspects of the underlying data. Calling older API versions will result in the stored data being incorrect for other versions of the API.
Is there an elegant way to deal with different API versions requiring data in different formats / structures?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With