50

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?

Won Jun Bae
  • 5,140
  • 6
  • 43
  • 49
  • 4
    Possible duplicate of [REST, HTTP DELETE and parameters](http://stackoverflow.com/questions/2539394/rest-http-delete-and-parameters) – Tim Biegeleisen Jan 22 '16 at 05:17
  • 1
    Are you asking how (the same way as with any other method) or if that is a good design choice (for that: http://stackoverflow.com/questions/2539394/rest-http-delete-and-parameters?rq=1) – Thilo Jan 22 '16 at 05:18
  • 1
    Please provide an example? It's a little tricky to understand exactly what you're asking. I *think* you're asking if it's RESTful to DELETE /photos?userId={userId}. Is that right? – Eric Stein Jan 22 '16 at 14:57
  • yes, or /photos?groupId={groupId} from the same endpoint – Won Jun Bae Jan 23 '16 at 21:57

1 Answers1

58

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.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52