I can't PUT or DELETE JSON, where do I look?

I’m making a webservice with JSON going in both directions for all requests, but seem to have run into a catch 22.

A) I try the request as “/questions/1.json?_method=put” but since the _method=put is not in the message body it doesn’t count.

B) I send the params as _method=put&{ “json”: “here” }

The request is recognize as a PUT, but the JSON can’t be interpreted.

C) I send the params as { “_method”:“put”, “json”: “here” }

The request isn’t recognized as a PUT, but the JSON can be parsed (it works using “curl -X PUT …”)

D) I try using GET (with the same approach as A) and it ignores the parameters and the message body.

Where should I attack this beast at?

AJ ONeal

Working Examples:

curl ‘http://www.whatsayye.com/questions.json?callback=jsonp12345’ \

-X “POST” \

-H “Content-Type: application/json” \

-H “Accept: application/json” \

-d “{ "question": { "question": "Created with curl JSON-ically", "url": "curljson" }}”

curl ‘http://www.whatsayye.com/questions/3.json’ \

-X “PUT” \

-H “Content-Type: application/json” \

-H “Accept: application/json” \

-d “{ "question": { "question": "Modified with curl JSON-ically", "url": "jsonrocks" }}”

Failing Examples:

curl ‘http://www.whatsayye.com/questions/3.json’ \

*-X “POST” *

-H “Content-Type: application/json” \

-H “Accept: application/json” \

*-d “_method=put” *

-d “{ "question": { "question": "Modified with curl JSON-ically", "url": "jsonWAYrocks" }}”

_method=put&{ “json”: “here” } will never work.

In a query string you need to assign it to something:

eg. _method=put&json={ “json”: “here” }

Johan

_method=put&{ "json": "here" } will never work.

In a query string you need to assign it to something:

eg. _method=put&json={ "json": "here" }

That won't every work either. In params_parser.rb the request is treated as wholly JSON, wholly XML, wholly YAML, or wholly whatever.

If it's JSON it doesn't look for params, it just shoves the parsed lump sum into a param called :_json I suppose I could patch that to handle this case, but I'm not sure at what level I should be looking.

But I'm not clear on the flow of the application. At what level is it deciding on what is an allowed request? and what is the symbol it expects? :_method => :WHAT???

I tried :_method => 'put' and :_method => :put. Neither worked

You are running into this because of a bug/misfeature. See this lighthouse ticket: https://rails.lighthouseapp.com/projects/8994/tickets/2289-_methodput-ignored-for-xhr-and-xml-requests

Apparently you can set an HTTP_X_HTTP_METHOD_OVERRIDE header, but that doesn't work for me either.