简体   繁体   中英

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?

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?

There's nothing wrong with using DELETE on a collection and filtering by query parameters. Neither the REST dissertation nor the HTTP spec say anything about not doing this.

This is different than the answer to the question that @Thilo linked to because the circumstances are different. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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