简体   繁体   English

添加或删除记录后,我应该返回RESTful API消息吗?

[英]RESTful API should I return a message after adding or deleting a record?

I would like to know if it a good practice (and really useful for a front end developer) return a message after adding or deleting a records using a RESTful API or if the status code 200 is enough. 我想知道这是一种好习惯(对于前端开发人员确实有用)是否在使用RESTful API添加或删除记录后返回消息,或者状态码200是否足够。

At the moment I am sending a message only in case of error example (404 Bad Request): 目前,我仅在出现错误示例(404错误请求)的情况下发送消息:

{
message: "The request is invalid."
modelState: {
locationId: [1]
0:  "LocationId is invalid. Make sure LocationId exists and it is in the right format."
-
}-
}

With message(200) 有留言(200)

{
message: "all ok"
}

Notes: I am using ApiController in asp.net MVC. 注意:我在asp.net MVC中使用ApiController。

A 200 response indicates there was no problem with the request. 响应为200表示请求没有问题。
For a DELETE, you could also use a 204 - No Content - Which implies the request was received, but I've nothing to say about it. 对于DELETE,您还可以使用204-无内容-这表示已接收到请求,但是我无话可说。

In the case of a POST, you could also return the newly resource in the body of the response. 对于POST,您还可以在响应的正文中返回新资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM