简体   繁体   English

在REST API中,DELETE方法可以有参数吗?

[英]In REST API, can DELETE methods have parameters?

In REST API, how do we create DELETE methods when parameters are required to determine what resources need to be deleted? 在REST API中,当需要参数来确定需要删除哪些资源时,我们如何创建DELETE方法?

For examples, photos can belong to both users and groups, and if we have an endpoint for photos, we will need additional information to figure out if we want to delete user photos or group photos, for example, 例如,照片可以属于用户和组,如果我们有照片的端点,我们将需要其他信息来确定我们是否要删除用户照片或组照片,例如,

 /photos?userId={userId}
 /photos?groupId={groupId}

is this a good Restful practice? 这是一个很好的休息练习吗?

Alternatively, should DELETE only happen through users/:id/photo or groups/:id/photo endpoints strictly? 或者,DELETE只能通过用户/:id / photo或groups /:id / photo端点严格执行吗?

There's nothing wrong with using DELETE on a collection and filtering by query parameters. 在集合上使用DELETE并通过查询参数进行过滤没有任何问题。 Neither the REST dissertation nor the HTTP spec say anything about not doing this. REST论文和HTTP规范都没有说明没有这样做。

This is different than the answer to the question that @Thilo linked to because the circumstances are different. 这与@Thilo所关联的问题的答案不同,因为情况不同。 That question was about including a "no, really, delete it!" 那个问题是关于包括“不,真的,删除它!” query parameter, which is inappropriate. 查询参数,这是不合适的。 You're using the query parameter to filter the results which should be deleted. 您正在使用查询参数来过滤应删除的结果。

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

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