-1

I have added versioning for the media types (xml/json) supported in my ReST services. The Accept header of the incoming request should have a media type with valid version to get a proper response in the specified format. The problem is that if the request contains a valid data format in the accept header but an invalid version (or no version specified) I have to give error response in that particular data format.

For example, let the valid media types be application/xml+v2 and application/json+v2. If the request header contains only application/xml or application/xml+v1 I have to give error response in xml and if the header contains application/json+v1 I have to give error response in json.

Naveed S
  • 5,106
  • 4
  • 34
  • 52

1 Answers1

1

Do you have to provide custom error message in case of wrong (unsupported) media type? Isn't it enough to use proper HTTP error code: 415 Unsupported Media Type and leave body of response empty?

In case if media type doesn't contain version I will assume that client request the newest available version.

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • I have to provide a custom error response. Currently I have a bean entry in rest-servlet.xml corresponding to each supported type with suitable converter. This can be given for each valid versioned media type. For all others I've included a wildcard entry into one of the converters. So whether it is **application/xml+v2** or **application/json+v2** the response obtained will be according to the converter. – Naveed S Oct 09 '13 at 12:08