Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In REST API, can DELETE methods have parameters?

Tags:

rest

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?

like image 560
Won Jun Bae Avatar asked Jan 22 '16 05:01

Won Jun Bae


People also ask

Can Delete method have query parameters?

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.

What is the use of Delete method in REST API?

In RESTful APIs resources are typically deleted using the HTTP DELETE method. The resource that should be deleted is identified by the request URI. DELETE is an idempotent HTTP operation. Sending the same DELETE request multiple times should only alter the server state once.

Can Delete method have request body?

This is an know scenario and Integration Server doesn't accept request body for HTTP DELETE Method. The only means to accept the content for DELETE method in IS is by passing the Query parameter.

Can delete API have payload?

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.


1 Answers

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.

like image 81
Eric Stein Avatar answered Oct 13 '22 07:10

Eric Stein