我想在 REST API 中删除一个时间跨度。
它没有 id 所以在“/timespan/”上调用 HTTP DELETE 是不可能的。实现是可能的,但我宁愿不付出额外的努力(需要一些数据库修改),除非有充分的理由添加它。
我考虑过在请求中使用“开始”和“结束”对“/timespan/”调用 DELETE,但据我所知,这与 REST 的工作方式冲突。
在“/timespan//”或诸如“/timespan/+”之类的连接上调用 DELETE 是否合法,或者我到底应该实现 ID 吗?
最佳答案
你是对的。 DELETE 不删除正文。
RFC 7231:
A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.
我已经看到你想做什么了
删除/sites/{siteId}/maintenance
但这确实不是最佳选择。如果 maintenance
是一种资源,则需要某种方式来唯一标识它。如果它是资源的属性,则您可以通过该资源上的 PUT
或 PATCH
将其删除。
关于rest - 在没有实体 ID 的 REST API 中删除最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31478866/