Let's say I have a resource that can have two different behaviors when delete is called
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?
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.
Use the sObject Rows resource to delete records. Specify the record ID and use the DELETE method of the resource to delete a record.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With