'Best' practice for restful POST response

前端 未结 2 411
予麋鹿
予麋鹿 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:36

    Returning the whole object on an update would not seem very relevant, but I can hardly see why returning the whole object when it is created would be a bad practice in a normal use case. This would be useful at least to get the ID easily and to get the timestamps when relevant. This is actually the default behavior got when scaffolding with Rails.

    I really do not see any advantage to returning only the ID and doing a GET request after, to get the data you could have got with your initial POST.

    Anyway as long as your API is consistent I think that you should choose the pattern that fits your needs the best. There is not any correct way of how to build a REST API, imo.

提交回复
热议问题