I'm building a REST API. actually I understand the the common guide and rule.
But i have issue with DELETE method, because I need to send the data over the body in the request, which DELETE method will ignore the body.
If you asking what data that makes me send it over body in DELETE method, is a 'url' and some other parameter. Of course the 'url' has id in the database, so i can use DELETE with no problem, like DELETE https://api.example.com/content/url:url_id
. But rather that pass the id, i chose to pass the url it self and some other param. my business logic and requirement force me to pass the url not the id in DELETE method.
so after reading, i find also some proxy blocking DELETE and PUT method. and also the HTML form only support GET and POST method.
i'm starting thinking that better to only use GET
and POST
in my REST API.
so i can user POST for delete and object or resource like this:
POST /content/delete/url
Body :
url : xxxx
param1 : xxxx
param2 : xxx
But in "REST API Design rulebook, O'reilly", page 18 said
"HTTP request methods should be used to indicate which CRUD function is performed"
The following anti-patterns exemplify what not to do:
GET /deleteUser?id=1234 GET /deleteUser/1234 POST /users/1234/delete
after searching and reading again, I came with some solution
using
X-HTTP-Method-Override
using api method name like flicker
(api.flickr.com/services/rest/?method=flickr.collections.getInfo)
andmailchimp(api.mailchimp.com/1.3/?method=campaignDelete)
I think I like solution 1, to use 'X-HTTP-Method-Override'. What do you think?
Google seem to use X-HTTP-Method-Override, rever to this https://developers.google.com/gdata/docs/2.0/basics
Flicker and Mailchimp use method name, like in solution 2