Best Practice: does anybody use GET with BODY?


(ian mayo) #1

Hi all,
I'm trying to collate my queries into a BODY JSON object, and then firing
that object via a GET call.

But, the REST utilities I'm using don't like supporting a BODY for GET
calls. In fact, Roy Fielding has recommended against it:
http://tech.groups.yahoo.com/group/rest-discuss/message/9962

The elasticsearch examples all use -d, with the JSON in a string. But, the
man page for CURL states that -d "sends the specified data in a POST
request":
http://unixhelp.ed.ac.uk/CGI/man-cgi?curl

So, it appears the use of -d isn't compliant with the spec for CURL.

Am I missing something here?

Whilst exploring the ES REST-API, is there a tidy way of collating a query
as JSON and then passing that into the GET?

cheers,
Ian


(Clinton Gormley) #2

Hiya

I'm trying to collate my queries into a BODY JSON object, and then
firing that object via a GET call.

What do you mean by "collate my queries"? Multiple queries? or do you
mean that you are building a single query?

But, the REST utilities I'm using don't like supporting a BODY for GET
calls. In fact, Roy Fielding has recommended against it:
http://tech.groups.yahoo.com/group/rest-discuss/message/9962

Personally, I disagree with the GET-can't-contain-a-body argument,
because the query string has a limited length. Conceptually, a search
is a GET, not a POST.

Javascript doesn't support it, but most other HTTP libraries do.

The elasticsearch examples all use -d, with the JSON in a string.
But, the man page for CURL states that -d "sends the specified data
in a POST request":
http://unixhelp.ed.ac.uk/CGI/man-cgi?curl

So, it appears the use of -d isn't compliant with the spec for CURL.

It defaults to a POST, but you can specify whichever method you want
with -X

Am I missing something here?

You have two options:

  1. search will also accept a POST request
  2. you can pass the request body as the query string parameter 'source'
    http://www.elasticsearch.org/guide/reference/api/index.html

Whilst exploring the ES REST-API, is there a tidy way of collating a
query as JSON and then passing that into the GET?

I don't know what this sentence means :slight_smile:

clint


(system) #3