3

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 parameters

In 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?

Community
  • 1
  • 1
w--
  • 6,427
  • 12
  • 54
  • 92
  • 1
    Why 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. – CodeGuru Aug 09 '13 at 09:35
  • yes I can do this. I was just wondering if there is an unknown-to-me best practice for this. – w-- Aug 09 '13 at 20:30

1 Answers1

1

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.

Community
  • 1
  • 1
  • yes. 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. – w-- Aug 09 '13 at 20:36
  • If 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. – theon Aug 12 '13 at 22:17
  • thanks @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. – w-- Aug 13 '13 at 05:54
  • 2
    Query 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. –  Aug 14 '13 at 06:39