In REST, should I return the representation in response to a PUT?

前端 未结 4 2013
猫巷女王i
猫巷女王i 2020-12-25 13:31

It is conceivable that another client also modified other aspects of the resource in the interim. So is it best practice to always include the full representation in the re

4条回答
  •  没有蜡笔的小新
    2020-12-25 13:55

    You may wish to consider returning a 303 See Other response with the Location header set to the URI of the updated resource (Post/Redirect/Get). This way the client receives the current state of the resource (if it chooses to follow the Location header) even if it has been edited in the interim, and is not in danger of resubmitting the request if using a browser.

    However, this pattern precludes sending the appropriate success code (200 OK, 202 Accepted, etc.) which may be useful to the client. Also, depending on your definition of REST, you may consider this to be non-standard practice.

    It's probably more appropriate if the clients are likely to be browsers operated by people.

提交回复
热议问题