What REST PUT/POST/DELETE calls should return by a convention?

前端 未结 5 2047
离开以前
离开以前 2020-12-04 05:54
  1. According to the \"REST ideology\" what should be in the response body for a PUT/POST/DELETE requests?

  2. What about return codes? Is HTTP_OK

5条回答
  •  广开言路
    2020-12-04 06:36

    Creating a resource is generally mapped to POST, and that should return the location of the new resource; for example, in a Rails scaffold a CREATE will redirect to the SHOW for the newly created resource. The same approach might make sense for updating (PUT), but that's less of a convention; an update need only indicate success. A delete probably only needs to indicate success as well; if you wanted to redirect, returning the LIST of resources probably makes the most sense.

    Success can be indicated by HTTP_OK, yes.

    The only hard-and-fast rule in what I've said above is that a CREATE should return the location of the new resource. That seems like a no-brainer to me; it makes perfect sense that the client will need to be able to access the new item.

提交回复
热议问题