I am building an API which I intend to upgrade over time. Is it ever reasonable to include a version number as an argument in the API?
I'm writing a key/value store API in Ruby, Java, Erlang, and C#. I want to build something that is extensible as I know there are many things I have not thought of yet that may have to be incorporated in the future. However, I want to know if there is a clean way of doing this and whether version numbers play a part in this too.
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)
API versioning is the practice of transparently managing changes to your API. Managing an API boils down to defining and evolving data contracts and dealing with breaking changes. The most effective way to evolve your API without breaking changes is to follow effective API change management principles.
The main difference between the API v1 and v2 is the way that the content is structured. The content structure for API v1 is more complex and meant to be used with one of our development kits.
You can do it, it's better (IMHO) if you just make your API backwards-compatible though. It's generally easier, as you don't need to branch on your side, based on the version number, you just re-implement the given method.
I suppose it's really quite implementation-specific (and also environment-specific). I'd do whatever seems easiest/better.
I'd say as long as your maintaining backwards compatibility in some fashion, then it's all good.
That could be reasonable if you're building an object oriented API and you give the version number to a factory. It's common in dynamic data centric APIs as well - you ask the library for data and have to indicate what format/version you want the data back as.
More commonly for "traditional" libraries(as in the ones you link to in your C/C++/.NET applications) done is:
provide an API to fetch the version number of the library. This allows the application to decide if it needs a newer/older version of the library.
be backwards compatible as long as you can.
Add functions, don't change them. If you have to add arguments/input or change behavior - create a new function rather, and keep the old one around.
when you eventually have to break backwards compatibility and get rid of all the old cruft kept around only for the sake of being backwards compatible, have a sane version scheme that clearly indicates incompatible versions.
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