You can alternatively offer multiple versions of the same functionality within one REST API by providing different methods with different Accepts and Produces attributes.
This time, in order to a get the new version, a client does not change the request URL. Instead, he changes the value of the standard Content-Type and Accept HTTP headers (as appropriate; read on for further explanation).
To get this to work, you need multiple methods with unique Method Names, identical Relative URI Paths, but different Accepts and Produces attributes:
Method Name
|
Relative URI Path
|
Accepts
|
Produces
|
PostCustomer-v1
|
/Customers
|
text/vnd.customer.v1+xml
|
text/vnd.customer.v1+xml
|
PostCustomer-v2
|
/Customers
|
text/vnd.customer.v2+xml
|
text/vnd.customer.v2+xml
|
In the example, the standard media type
text/xml
has been replaced by vendor-specific media types, or Vendor MIME Types, that indicate versioning, namely
text/vnd.customer.v1+xml
text/vnd.customer.v2+xml
In the added part, 'vnd' is a conventional abbreviation for 'Vendor MIME Type'. 'customer' is any string that refers to the versioned functionality; many times, the new version will offer the same functionality but operate on a different version of the data, in which case it is good practice to make this string refer to the appropriate new structure used in the method's new parameters. 'v1' is a conventional abbreviation for "version 1".
At runtime, the client matches the Accepts value by setting the Content-Type HTTP header to the same value, and the Produces value by setting the Accept HTTP header.
|