'Best' practice for restful POST response

前端 未结 2 409
予麋鹿
予麋鹿 2020-12-07 07:25

So nothing new here I am just trying to get some clarification and cannot seem to find any in other posts.

I am creating a new resource restulfully, say:

<         


        
2条回答
  •  感情败类
    2020-12-07 07:40

    Returning the new object fits with the REST principle of "Uniform Interface - Manipulation of resources through representations." The complete object is the representation of the new state of the object that was created.

    There is a really excellent reference for API design, here: Best Practices for Designing a Pragmatic RESTful API

    It includes an answer to your question here: Updates & creation should return a resource representation

    It says:

    To prevent an API consumer from having to hit the API again for an updated representation, have the API return the updated (or created) representation as part of the response.

    Seems nicely pragmatic to me and it fits in with that REST principle I mentioned above.

提交回复
热议问题