Please add support for request body when executing a delete

932 views
Skip to first unread message

A. Miller

unread,
May 2, 2012, 12:08:50 PM5/2/12
to RestSharp
I am trying to call a restful api's DELETE method which takes an array
of JSON objects in the request body. This wasn't working with
restsharp but I was able to get it to work with a basic HttpWebRequest
the old-fashion unfriendly/ugly code way. After a little bit of
reserach reading your code, I noticed that the Http class's method
"public HttpResponse Delete()" does not write anything to the request
body. Is this by design? Can you add support to be able to send a
request body with a delete call?

Thanks in advance.

Andrew Young

unread,
May 2, 2012, 1:48:15 PM5/2/12
to rest...@googlegroups.com
I don't think we want to be sending a request body for DELETE unless it is necessary. Most cases DELETE would not have a request body. The specs don't mention whether it should or should not require a body.

We could put some smarts into Delete to add a body if needed but I'd like some input from others about this.

A. Miller

unread,
May 2, 2012, 6:37:21 PM5/2/12
to RestSharp
Yea, I know it is kind of wonky as DELETE is supposed to imply
deleting the resource. So I'm pretty sure it is by design that
RestSharp does not write anything into the body. However, where
parameters belong is also one of those things that isn't really "in
stone" so to speak. Deleteing a resource that has a hundred
parameters would result in some pretty big urls, while putting it into
the request body could allow it to be a little cleaner (at least
reading the url would be cleaner).

Anyway, I'll just work around it if I need to. I was just curious if
it is ok to add support for it, or if there is a compelling reason to
not support it.

Thanks for the reply.

Adam

Lee Whitney

unread,
May 2, 2012, 6:43:57 PM5/2/12
to <restsharp@googlegroups.com>, RestSharp
It's not wonky it's just less commonly needed.

It's bad if not necessary, for example the API could have been designed more simply without it.

It's an edge case but not against spec.

John Sheehan

unread,
May 2, 2012, 7:13:20 PM5/2/12
to rest...@googlegroups.com
I originally decided not to support this because there are known problems with intermediaries stripping bodies on anything other than PUT or POST and that would result in unexpected side effects.


The problem is that AddParameter() does different things for PUT/POST and GET/HEAD/DELETE/etc and if you move DELETE into the first group, that will break the current 'contract' for how things work.

If someone can come up with a way to support this that would not break existing apps and doesn't involve an option (RestClient.AddDeleteParameterToBody is not an option) we can discuss it further. Maybe a new ParameterType that's explicitly Post instead of GetOrPost?

Neal Tibrewala

unread,
May 3, 2012, 1:16:33 PM5/3/12
to rest...@googlegroups.com
I'm confused.  If you make a Delete request, and do a normal AddParameter with the RequestBody type, why won't it work?  If it's not supported now, then it doesn't break anything by supporting it, right?

Andrew Young

unread,
May 3, 2012, 1:26:07 PM5/3/12
to rest...@googlegroups.com
RestSharp prepares DELETEs as a GET style request. This means it won't add a request body regardless of how you call AddParameter().

Neal Tibrewala

unread,
May 3, 2012, 9:41:45 PM5/3/12
to rest...@googlegroups.com
I understand that, I'm wondering why John thinks allowing deleteRequest.AddParameter(foo, body, ParameterType.RequestBody) breaks anything about any existing contract.  since it's not supported now, so one is doing it, so allowing it to happen isn't going to break anyone.

As for the mechanism for safety of proxies, I think that's an excellent Option to add, not something specific to delete bodies, but rather:

RestClient.CompatibleProxyMode = false;  // Allows requests that may not pass through all proxies

- Neal

John Sheehan

unread,
May 5, 2012, 1:51:29 AM5/5/12
to rest...@googlegroups.com
AddParameter(foo, body, ParameterType.RequestBody) doesn't do what you
think it does. It's just a (really, really bad) container that passes
through content to be written to the body directly. This was a bad,
terrible, design decision. It doesn't handle individual parameters.

I think the solution to this is to add ParameterType.Url and
ParameterType.Body and make sure that those are guaranteed to get
written to the specified location instead of depending on the
method-specific logic.

Who wants it?

Jordan Griffin

unread,
Aug 3, 2012, 4:49:03 PM8/3/12
to rest...@googlegroups.com
I second this. Ran into this same issue with POST where I'd like to send some query parameters along with a JSON post body.


Jordan

Kevin Whalley

unread,
Mar 24, 2013, 10:50:17 PM3/24/13
to rest...@googlegroups.com
Hi John,
 
I ran into this particular issue while working on a client for Github. It's necessary to pass a JSON document in the body of a DELETE request. Did you ever resolve this issue?
 
Kevin W

Cezar Floroiu

unread,
Apr 5, 2013, 8:01:13 AM4/5/13
to rest...@googlegroups.com, kjw...@gmail.com
Hello,

I need this too!

I need to do a DELETE and pass an ID param in the body of the request.  Do not ask my why, but this is how was implemented in the services I need to consume.  When can we expect to have RestSharp support this ? For me this is a blocker right now.

Thanks
Cezar

Simon Dahlbacka

unread,
Aug 27, 2013, 6:36:40 AM8/27/13
to rest...@googlegroups.com
I would need this too, anyone working on this?

/Simon
Reply all
Reply to author
Forward
0 new messages