简体   繁体   English

很奇怪 http 删除 rest 操作 - 删除有很多参数

[英]Very strange http delete rest operation - delete with a lot parameters

The analysis team worked on some specification which sounds a bit strange to me.分析团队制定了一些对我来说听起来有点奇怪的规范。

I have to delete a resource on a database table.我必须删除数据库表上的资源。 I have the id of the rekord as input parameter.我有 rekord 的 id 作为输入参数。

This is straight forward http delete operation.这是直截了当的 http 删除操作。

DELETE http://my-url/{id}

They want to add as input parameters some other values, present in the rekord, because, they say "the delete operation is very delicate in this case and we want to be sure to exclude errors in frontend, the id passed is should be the id of the values of the rekord passed".他们想添加一些其他值作为输入参数,出现在 rekord 中,因为,他们说“在这种情况下删除操作非常微妙,我们希望确保排除前端的错误,传递的 id 应该是 id rekord 的值通过”。

There were a lot of internal discussion about this requirement.关于这个要求有很多内部讨论。 Dishes flew between partecipants.菜肴在参与者之间飞来飞去。 Anyway we have to satisfy it.无论如何,我们必须满足它。

I know this is not more RESTful operation.我知道这不是更多的 RESTful 操作。

I modified like this:我这样修改:

DELETE http://my-url/{id}
REQEUST BODY
{
    "myProperty1" = 123,
    "myProperty2" = "VALUE",
    ...
}

Swagger generation gets angry about DELETE with REQUEST BODY. Swagger 一代对 DELETE with REQUEST BODY 感到愤怒。

I have to switch to我必须切换到

  • POST operation with REQUEST BODY使用 REQUEST BODY 进行 POST 操作
  • DELETE operation with some REQUEST PARAMS带有一些 REQUEST PARAMS 的 DELETE 操作

The development team likes to stay as long as possible in a RESTful environment.开发团队喜欢尽可能长时间地呆在 RESTful 环境中。 What would be better not to be out of tune?什么会更好不走调?

ANY OTHER ADVICE OR SOLUTION WE DID NOT THINK WOULD BE APPRECIATED.我们认为不会受到赞赏的任何其他建议或解决方案。

Swagger generation gets angry about DELETE with REQUEST BODY. Swagger 一代对 DELETE with REQUEST BODY 感到愤怒。

Yup, that's right.是的,没错。

A payload within a DELETE request message has no defined semantics -- RFC 7231 DELETE 请求消息中的有效负载没有定义的语义——RFC 7231

DELETE is about decoupling a URI from its representations. DELETE 是关于将 URI 与其表示分离。 It's somewhat analogous to removing a key from a map/dictionary, or a symbolic link in a file system.这有点类似于从地图/字典中删除键或文件系统中的符号链接。 It tells a web server to stop serving a particular web page.它告诉 web 服务器停止为特定的 web 页面提供服务。

It's normally easy to figure out what the identifier should be for a DELETE request;通常很容易弄清楚 DELETE 请求的标识符应该是什么。 it will be the same identifier you use to look up a representation with a GET request.它将与您用于通过 GET 请求查找表示的标识符相同。


DELETE is an action with semantics in the transfer of documents over a network domain. DELETE 是在网络域上传输文档时具有语义的操作。

Note this observation included in the standard:请注意标准中包含的这一观察:

Relatively few resources allow the DELETE method -- its primary use is for remote authoring environments, where the user has some direction regarding its effect.相对较少的资源允许使用 DELETE 方法——它的主要用途是远程创作环境,用户对其效果有一定的指导。

If what you are trying to do is pass a message to your server, with a payload, so that the server can do something clever, you should probably be using POST, rather than DELETE.如果您要做的是将带有有效负载的消息传递给您的服务器,以便服务器可以做一些聪明的事情,那么您可能应该使用 POST,而不是 DELETE。

Remember: it is okay to use POST .请记住:可以使用 POST The world wide web was catastrophically successful using little more than GET and POST .世界范围内的 web 仅使用GET 和 POST就取得了灾难性的成功。


They want to add as input parameters some other values, present in the rekord, because, they say "the delete operation is very delicate in this case and we want to be sure to exclude errors in frontend, the id passed is should be the id of the values of the rekord passed".他们想添加一些其他值作为输入参数,出现在 rekord 中,因为,他们说“在这种情况下删除操作非常微妙,我们希望确保排除前端的错误,传递的 id 应该是 id rekord 的值通过”。

It's possible that what is being sought here is a conditional delete.这里所寻求的可能是有条件的删除。 We have standardized headers that can be used by validators to determine if the DELETE request and the current state of the resource "match".我们有标准化的标头,验证器可以使用这些标头来确定 DELETE 请求和资源的当前 state 是否“匹配”。

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

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