-1

What's a good approach to exposing web services of different versions on the same URL? I don't want to have different URLs for different versions so I can change which version consumers are using from the server side. If version is in the URL, it's not optional and I can't provide a sensible default.

Offhand I can think of:

  1. Putting a version parameter in the query string
  2. Putting a version parameter in the post body

Are either of these good choices, or is there a different approach I should be taking?

Let me also add another question. How would a framework/program execute different versions if they reside in different JAR or EAR versions of the code?

2

1 Answer 1

0

It's not an altogether uncommon practice to use headers for version specification on web services these days. Query string is also one I've seen used; both of these rely on the concept of a "sensible default" which is typically the latest version when the header or query string are not provided.

Another approach can be to have versions tied to consumers so if you require some authentication token on all requests, along with using it to identify who the consumer is, it can be used to identify what version of the API they have selected to use. This approach has good and bad sides to it as depending on how consumers use it, they may wish to use multiple versions at the same time (perhaps one call they want to use a later service version, while all the other calls they're still on an older one).

I would strongly discourage using a parameter in the post body because this would require you to make every single request a post, which is bad form for REST. If you're using SOAP however, then actually the SOAP headers would be the perfect place to put this as you can't rely on HTTP headers since SOAP can be transmitted via non-HTTPtransports (e-mail, TCP, MQ, etc).

tl;dr

If it's REST, use HTTP headers or query string; whichever's easier for you. For SOAP use the SOAP headers. If none of these are viable choices, I'd say you'll have to fall back on the classic of using different URLs for different versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.