REST and DELETE -> passing parameters
11,219
Metadata by its very name is data about a Resource. Using HTTP, such data belongs into HTTP headers.
Since the X-
prefix is deprecated, just choose sensible header names for your metadata.
Related videos on Youtube
Author by
w--
Updated on May 25, 2022Comments
-
w-- almost 2 years
So this question has been asked numerous times in SO and elsewhere. On SO this is probably the question with the most comprehensive answers and comments.
REST, HTTP DELETE and parametersIn my scenario I want to add information to a delete request, not to identify the resource, but as meta data. Specifically, just some additional data the delete operation should record in a log.
Based on everything I've read putting any parameters as part of the DELETE request goes against best practices. What would be the best practice in this scenario?
-
CodeGuru over 10 yearsWhy don't you just create it as POST call and do delete at code side, so you can pass data which you want as part of body.
-
w-- over 10 yearsyes I can do this. I was just wondering if there is an unknown-to-me best practice for this.
-
-
w-- over 10 yearsyes. I thought aobut using headers and felt this was the most semantically appropriate approach. I wanted to avoid doing this, however. I'm implementing using django-rest-framework and if i used custom headers, would need to modify boilerplate for the browsable api templates (or have to roll my own) which I'd like to avoid for now.
-
theon over 10 yearsIf it is a complex data structure you want to send, then JSON in the request body makes sense. If it is just a couple of fields, then I'd agree that headers would be most suitable. However if you don't want to use them, then really your only other choice is query string params.
-
w-- over 10 yearsthanks @theon. After your comments on the query strings I looked around a little and it seems many also agree that querystrings for a delete method request are acceptable practice as well. For whatever reason, I didn't think they query string params appropriate for anything other than a GET request.
-
Admin over 10 yearsQuery parameters are a part of the URI. The URI identifies a resource. You can use query parameters with a
DELETE
if you want to delete the resource/resources identified by the complete URI including the query parameters.