Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful delete strategy

Tags:

rest

Let's say I have a resource that can have two different behaviors when delete is called

  1. The resource is deleted.
  2. The resource is moved to the recycle bin.

How would model it in a REST compliant way?

I thought about the following solution:

DELETE /myresource     

moves the resource to the recycle bin (default behavior)

DELETE /myresource?force-delete=true  

forces delete on the resource.

Is that REST compliant? I have never seen query parameters in the URL when calling DELETE, is that OK?

like image 581
LiorH Avatar asked Feb 04 '09 17:02

LiorH


People also ask

What is Delete method in REST API?

The Delete method requests the server to delete the resource identified by the request URI. The resource deletion depends on the server and is deleted if prescribed for deletion. Additionally, the restoration implementation of the resource is also considerable.

How do I delete data from REST API?

Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.

What should API return for delete?

DELETE API Response Codes. A successful response of DELETE requests SHOULD be an HTTP response code 200 (OK) if the response includes an entity describing the status. The status should be 202 (Accepted) if the action has been queued.


2 Answers

Your idea is fine, but I think a custom request header would be a little more appropriate. Query parameters are better suited to, well, parameters.

A custom request header would look something like this:

DELETE /myresource
X-Really-Delete: Yup
like image 53
Avi Flax Avatar answered Sep 23 '22 15:09

Avi Flax


A pure REST strategy should prefer non changing resources. In my opinion, you are not changing the resource by appending a parameter, so it sounds like good strategy to me.

If you were to perform the same action like so:

DELETE /myresource.force

that would act like another resource, which wouldn't be optimal.

like image 24
ern Avatar answered Sep 23 '22 15:09

ern