Alternative bodies for HTTP PUT

I am developing a REST-ful web service and I have a question about the HTTP PUT method.

I want people to be able to submit content using the app / form request body. However, the default answer will be in application / xml.

It is acceptable?

Evert

0
rest put
source share
2 answers

Content types are important only within a single request. All they do is describe the format of the content they send.

Your web service should provide the answer most suitable for the client request that it can provide. The client request should include an Accept header, which describes the valid content types. If your service cannot provide any content types in this header, return 406 Not Acceptable

In your situation, if your GET client requests include application/xml in the Accept header, then it is ok to respond with application/xml , regardless of any PUT request made on the requested resources.

EDIT:

The definition of the status code for 406 Not Acceptable includes a note with the following:

Note. The HTTP / 1.1 server is allowed to return responses that are unacceptable according to the headers of the hosts sent to the request. In some cases, this may even be preferable to 406. User agents are advised to check the headers of the incoming response to determine if this is acceptable.

This way you can return application/xml whenever you want.

+2
source

RESTful services should use the correct HTTP method (GET, HEAD, PUT, DELETE or POST) for the action, make sure that any information about the scope is contained in the URI and make sure that the HTTP message wrapper does not contain another envelope, i.e. e. SOAP

Roy Fieldings 2000 Ph.D. dissertation: architectural styles and design of network architectural solutions forms the basis of REST.

0
source

All Articles