-1

I'm wondering why when I use a route to a controller that uses a GET method, Rails strips the request's body out. If I change the route definition to POST, the body comes through.

I am trying to send a JSON encoded options hash to GET /customer/find so that it returns a list of customers. It's not changing anything, so it shouldn't be a POST.

Someone please explain what I'm missing here.

EDIT:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html details that a POST request doesn't have to create something, however it should return 201 if it does. Status codes of 200 (OK), 204(No Content) are valid for POST methods as well. Question awarded to aVenger for his comment on his answer.

WedTM
  • 2,587
  • 5
  • 37
  • 54
  • See here on why including a body in your GET request is a bad idea: http://stackoverflow.com/questions/978061/http-get-with-request-body – Elad Aug 19 '11 at 08:47
  • *GET* is using without body as usual. there is no way to encapsulate something in the request. – Anatoly Aug 19 '11 at 08:49
  • 1
    "It's not changing anything, so it shouldn't be a POST" should read "The options do not affect the result sent, so it shouldn't be a POST". If you really want to use a GET, pass the parameters in the query string, else switch to POST. – Benoit Garret Aug 19 '11 at 09:46
  • You should be url-encoding the options hash and passing it as a query string in a GET request if you're just retrieving information about resources. http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html – tomblomfield Jan 17 '12 at 16:18

1 Answers1

1

Why don't you just send your json hash as a request parameter? If it's too big, you should use POST anyway.

wanderfalke
  • 878
  • 8
  • 8
  • 2
    GET is idempotent, POST is not. POST is generally used to change something. This is an ideology. – Anatoly Aug 19 '11 at 10:33
  • a POST request moght change something, is doesn't have to. – wanderfalke Aug 19 '11 at 10:51
  • According to this: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html, aVenger is correct. POST doesn't HAVE to create something, but if it does, it should return with status 201, if not, it can return with status 200, or 204 if no-content. – WedTM Aug 19 '11 at 19:19