RESTful web services best way to return operation result?

I am developing a RESTful API, and I would like to know what is the most RESTful way to return operation data.

eg. a resource operation occurs when some data is sent to a URL. HTTP status codes indicate success or failure of the operation. But besides success / failure, I need to provide some other information to the client, such as an identification number.

So my question is, should the ID number be returned in the XML document in the response content, or should it be returned in some custom HTTP header fields? Which is more in line with REST principles? Or am I free to choose.

+4
source share
3 answers

Returning an object is an absolutely correct response to HTTP POST.

You also do not need to return XML, you can just use the text / plain text type and just return the string value.

Using a heading will require you to define a new custom heading that is not ideal. I expect that it will be easier for clients to analyze the body of the response than extracting information from the header.

+3
source

An XML document makes the most sense.

0
source

If this is just an identification number, it will save the overhead to do so as an HTTP header. Creating the right XML document for just one number would add much more overhead for the request.

0
source

Source: https://habr.com/ru/post/1307404/


All Articles