Zinc GET request with body in the request.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Zinc GET request with body in the request.

Paul DeBruicker
I'm making an elasticsearch client and they utilize JSON bodies in the
GET requests to their server to search and do other things.  An example
of that is the second code block here:

http://www.elasticsearch.org/guide/reference/api/search/


Is there a way to include a body with a GET request using Zinc?


Making this:

ZnClient>>#get:contents:
        "Execute an HTTP GET request on url with the contents in a body and
return the response #contents."

        ^ self
                url: url;
                contents: object;
                get


(unsurprisingly) doesn't work right away.


In elasticsearch it is possible to make a URI request for searching but
it is a more limited interface than including the JSON body.


Thanks

Paul

Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

Camillo Bruni-3
I just had a quick peek, shouldn't that be all post requests?

get does not support a body, you have to pass everything as url parameters.

On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:

> I'm making an elasticsearch client and they utilize JSON bodies in the
> GET requests to their server to search and do other things.  An example
> of that is the second code block here:
>
> http://www.elasticsearch.org/guide/reference/api/search/
>
>
> Is there a way to include a body with a GET request using Zinc?
>
>
> Making this:
>
> ZnClient>>#get:contents:
> "Execute an HTTP GET request on url with the contents in a body and
> return the response #contents."
>
> ^ self
> url: url;
> contents: object;
> get
>
>
> (unsurprisingly) doesn't work right away.
>
>
> In elasticsearch it is possible to make a URI request for searching but
> it is a more limited interface than including the JSON body.
>
>
> Thanks
>
> Paul
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

Paul DeBruicker
I don't know what should be but if you substitute -XPOST or just -POST
for the -XGET then the search fails and you get no results.  the -X just
forces curl to use the HTTP method that follows.


It does seem to be contrary to the HTTP spec but  I'm not sure of that
either.





On 04/23/2013 11:52 AM, Camillo Bruni wrote:

> I just had a quick peek, shouldn't that be all post requests?
>
> get does not support a body, you have to pass everything as url parameters.
>
> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>> I'm making an elasticsearch client and they utilize JSON bodies in the
>> GET requests to their server to search and do other things.  An example
>> of that is the second code block here:
>>
>> http://www.elasticsearch.org/guide/reference/api/search/
>>
>>
>> Is there a way to include a body with a GET request using Zinc?
>>
>>
>> Making this:
>>
>> ZnClient>>#get:contents:
>> "Execute an HTTP GET request on url with the contents in a body and
>> return the response #contents."
>>
>> ^ self
>> url: url;
>> contents: object;
>> get
>>
>>
>> (unsurprisingly) doesn't work right away.
>>
>>
>> In elasticsearch it is possible to make a URI request for searching but
>> it is a more limited interface than including the JSON body.
>>
>>
>> Thanks
>>
>> Paul
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

Sven Van Caekenberghe-2
Paul,

Well, it is against the spec IMHO: there should be no body with GET or HEAD.

That is why the body is cleared in ZnClient>>#method: in those cases (ZnClient is meant to be reused for multiple requests).

But by using a small detour it is possible:

ZnClient new
        logToTranscript;
        url: 'http://zn.stfx.eu/echo';
        method: #GET;
        contents: 'Foobar';
        execute.

If you inspect the reply to /echo you will notice that the server acknowledges receiving an entity. This should do the trick.

HTH,

Sven

PS: You can use ZnClient>>#contentWriter: to convert from Smalltalk to JSON automagically...

On 23 Apr 2013, at 21:02, Paul DeBruicker <[hidden email]> wrote:

> I don't know what should be but if you substitute -XPOST or just -POST
> for the -XGET then the search fails and you get no results.  the -X just
> forces curl to use the HTTP method that follows.
>
>
> It does seem to be contrary to the HTTP spec but  I'm not sure of that
> either.
>
>
>
>
>
> On 04/23/2013 11:52 AM, Camillo Bruni wrote:
>> I just had a quick peek, shouldn't that be all post requests?
>>
>> get does not support a body, you have to pass everything as url parameters.
>>
>> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>>> I'm making an elasticsearch client and they utilize JSON bodies in the
>>> GET requests to their server to search and do other things.  An example
>>> of that is the second code block here:
>>>
>>> http://www.elasticsearch.org/guide/reference/api/search/
>>>
>>>
>>> Is there a way to include a body with a GET request using Zinc?
>>>
>>>
>>> Making this:
>>>
>>> ZnClient>>#get:contents:
>>> "Execute an HTTP GET request on url with the contents in a body and
>>> return the response #contents."
>>>
>>> ^ self
>>> url: url;
>>> contents: object;
>>> get
>>>
>>>
>>> (unsurprisingly) doesn't work right away.
>>>
>>>
>>> In elasticsearch it is possible to make a URI request for searching but
>>> it is a more limited interface than including the JSON body.
>>>
>>>
>>> Thanks
>>>
>>> Paul
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

NorbertHartl
In reply to this post by Camillo Bruni-3

Am 23.04.2013 um 20:52 schrieb Camillo Bruni <[hidden email]>:

> I just had a quick peek, shouldn't that be all post requests?
>
> get does not support a body, you have to pass everything as url parameters.
>
Can you elaborate on this? Why does GET not "support" a body? There is just no explicit mentioning of it in the rfc but on the same track there is no exclusion for that scenario.

Norbert

> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>> I'm making an elasticsearch client and they utilize JSON bodies in the
>> GET requests to their server to search and do other things.  An example
>> of that is the second code block here:
>>
>> http://www.elasticsearch.org/guide/reference/api/search/
>>
>>
>> Is there a way to include a body with a GET request using Zinc?
>>
>>
>> Making this:
>>
>> ZnClient>>#get:contents:
>> "Execute an HTTP GET request on url with the contents in a body and
>> return the response #contents."
>>
>> ^ self
>> url: url;
>> contents: object;
>> get
>>
>>
>> (unsurprisingly) doesn't work right away.
>>
>>
>> In elasticsearch it is possible to make a URI request for searching but
>> it is a more limited interface than including the JSON body.
>>
>>
>> Thanks
>>
>> Paul
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

Sven Van Caekenberghe-2

On 23 Apr 2013, at 21:21, Norbert Hartl <[hidden email]> wrote:

>
> Am 23.04.2013 um 20:52 schrieb Camillo Bruni <[hidden email]>:
>
>> I just had a quick peek, shouldn't that be all post requests?
>>
>> get does not support a body, you have to pass everything as url parameters.
>>
> Can you elaborate on this? Why does GET not "support" a body? There is just no explicit mentioning of it in the rfc but on the same track there is no exclusion for that scenario.

Technically you can include a body with a GET or any method, but it should not have a semantic meaning, according to Roy Fielding:

http://tech.groups.yahoo.com/group/rest-discuss/message/9962

;-)

> Norbert
>> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>>> I'm making an elasticsearch client and they utilize JSON bodies in the
>>> GET requests to their server to search and do other things.  An example
>>> of that is the second code block here:
>>>
>>> http://www.elasticsearch.org/guide/reference/api/search/
>>>
>>>
>>> Is there a way to include a body with a GET request using Zinc?
>>>
>>>
>>> Making this:
>>>
>>> ZnClient>>#get:contents:
>>> "Execute an HTTP GET request on url with the contents in a body and
>>> return the response #contents."
>>>
>>> ^ self
>>> url: url;
>>> contents: object;
>>> get
>>>
>>>
>>> (unsurprisingly) doesn't work right away.
>>>
>>>
>>> In elasticsearch it is possible to make a URI request for searching but
>>> it is a more limited interface than including the JSON body.
>>>
>>>
>>> Thanks
>>>
>>> Paul
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

NorbertHartl
In reply to this post by Sven Van Caekenberghe-2

Am 23.04.2013 um 21:21 schrieb Sven Van Caekenberghe <[hidden email]>:

> Paul,
>
> Well, it is against the spec IMHO: there should be no body with GET or HEAD.
>
Well, it is a "must not" for HEAD and a "not mentioned at all" for GET. The "should not" use a body for GET is meant that a GET request should only include query parameters or paramterization of a retrieval action. So it is pretty unclear what should be done. I translate the same thing as: A request body for GET request is ok if the body contains only query parameters and does not alter system state (just be idempotent).
The same problem goes by "simply" choosing POST for the same request. The interpretation of the URI is different for GET and POST. In case of elasticsearch you really query the entity that is in the URI. For POST it isn't.

Norbert
 

> That is why the body is cleared in ZnClient>>#method: in those cases (ZnClient is meant to be reused for multiple requests).
>
> But by using a small detour it is possible:
>
> ZnClient new
> logToTranscript;
> url: 'http://zn.stfx.eu/echo';
> method: #GET;
> contents: 'Foobar';
> execute.
>
> If you inspect the reply to /echo you will notice that the server acknowledges receiving an entity. This should do the trick.
>
> HTH,
>
> Sven
>
> PS: You can use ZnClient>>#contentWriter: to convert from Smalltalk to JSON automagically...
>
> On 23 Apr 2013, at 21:02, Paul DeBruicker <[hidden email]> wrote:
>
>> I don't know what should be but if you substitute -XPOST or just -POST
>> for the -XGET then the search fails and you get no results.  the -X just
>> forces curl to use the HTTP method that follows.
>>
>>
>> It does seem to be contrary to the HTTP spec but  I'm not sure of that
>> either.
>>
>>
>>
>>
>>
>> On 04/23/2013 11:52 AM, Camillo Bruni wrote:
>>> I just had a quick peek, shouldn't that be all post requests?
>>>
>>> get does not support a body, you have to pass everything as url parameters.
>>>
>>> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>>>> I'm making an elasticsearch client and they utilize JSON bodies in the
>>>> GET requests to their server to search and do other things.  An example
>>>> of that is the second code block here:
>>>>
>>>> http://www.elasticsearch.org/guide/reference/api/search/
>>>>
>>>>
>>>> Is there a way to include a body with a GET request using Zinc?
>>>>
>>>>
>>>> Making this:
>>>>
>>>> ZnClient>>#get:contents:
>>>> "Execute an HTTP GET request on url with the contents in a body and
>>>> return the response #contents."
>>>>
>>>> ^ self
>>>> url: url;
>>>> contents: object;
>>>> get
>>>>
>>>>
>>>> (unsurprisingly) doesn't work right away.
>>>>
>>>>
>>>> In elasticsearch it is possible to make a URI request for searching but
>>>> it is a more limited interface than including the JSON body.
>>>>
>>>>
>>>> Thanks
>>>>
>>>> Paul
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

NorbertHartl
In reply to this post by Sven Van Caekenberghe-2

Am 23.04.2013 um 21:30 schrieb Sven Van Caekenberghe <[hidden email]>:

>
> On 23 Apr 2013, at 21:21, Norbert Hartl <[hidden email]> wrote:
>
>>
>> Am 23.04.2013 um 20:52 schrieb Camillo Bruni <[hidden email]>:
>>
>>> I just had a quick peek, shouldn't that be all post requests?
>>>
>>> get does not support a body, you have to pass everything as url parameters.
>>>
>> Can you elaborate on this? Why does GET not "support" a body? There is just no explicit mentioning of it in the rfc but on the same track there is no exclusion for that scenario.
>
> Technically you can include a body with a GET or any method, but it should not have a semantic meaning, according to Roy Fielding:
>
> http://tech.groups.yahoo.com/group/rest-discuss/message/9962
>
Well, there is just the statement of Roy Fielding that it isn't useful but no explanation. I would be very interested in a proper answer. I can follow the line of reasoning not to include a body in a GET request. The situation in case of JSON is just that is less awkward to use for complex parameterization with JSON instead of putting everything in query parameters. So until there is a good explanation why you shouldn't I would be all for it :)

Norbert

> ;-)
>
>> Norbert
>>> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>>>> I'm making an elasticsearch client and they utilize JSON bodies in the
>>>> GET requests to their server to search and do other things.  An example
>>>> of that is the second code block here:
>>>>
>>>> http://www.elasticsearch.org/guide/reference/api/search/
>>>>
>>>>
>>>> Is there a way to include a body with a GET request using Zinc?
>>>>
>>>>
>>>> Making this:
>>>>
>>>> ZnClient>>#get:contents:
>>>> "Execute an HTTP GET request on url with the contents in a body and
>>>> return the response #contents."
>>>>
>>>> ^ self
>>>> url: url;
>>>> contents: object;
>>>> get
>>>>
>>>>
>>>> (unsurprisingly) doesn't work right away.
>>>>
>>>>
>>>> In elasticsearch it is possible to make a URI request for searching but
>>>> it is a more limited interface than including the JSON body.
>>>>
>>>>
>>>> Thanks
>>>>
>>>> Paul
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Zinc GET request with body in the request.

Sven Van Caekenberghe-2

On 23 Apr 2013, at 21:42, Norbert Hartl <[hidden email]> wrote:

>
> Am 23.04.2013 um 21:30 schrieb Sven Van Caekenberghe <[hidden email]>:
>
>>
>> On 23 Apr 2013, at 21:21, Norbert Hartl <[hidden email]> wrote:
>>
>>>
>>> Am 23.04.2013 um 20:52 schrieb Camillo Bruni <[hidden email]>:
>>>
>>>> I just had a quick peek, shouldn't that be all post requests?
>>>>
>>>> get does not support a body, you have to pass everything as url parameters.
>>>>
>>> Can you elaborate on this? Why does GET not "support" a body? There is just no explicit mentioning of it in the rfc but on the same track there is no exclusion for that scenario.
>>
>> Technically you can include a body with a GET or any method, but it should not have a semantic meaning, according to Roy Fielding:
>>
>> http://tech.groups.yahoo.com/group/rest-discuss/message/9962
>>
> Well, there is just the statement of Roy Fielding that it isn't useful but no explanation. I would be very interested in a proper answer. I can follow the line of reasoning not to include a body in a GET request. The situation in case of JSON is just that is less awkward to use for complex parameterization with JSON instead of putting everything in query parameters. So until there is a good explanation why you shouldn't I would be all for it :)

Yeah, it is not really forbidden and it can be useful, so even if it is pretty uncommon, it should be allowed/supported, in a pinch.

> Norbert
>> ;-)
>>
>>> Norbert
>>>> On 2013-04-23, at 20:41, Paul DeBruicker <[hidden email]> wrote:
>>>>> I'm making an elasticsearch client and they utilize JSON bodies in the
>>>>> GET requests to their server to search and do other things.  An example
>>>>> of that is the second code block here:
>>>>>
>>>>> http://www.elasticsearch.org/guide/reference/api/search/
>>>>>
>>>>>
>>>>> Is there a way to include a body with a GET request using Zinc?
>>>>>
>>>>>
>>>>> Making this:
>>>>>
>>>>> ZnClient>>#get:contents:
>>>>> "Execute an HTTP GET request on url with the contents in a body and
>>>>> return the response #contents."
>>>>>
>>>>> ^ self
>>>>> url: url;
>>>>> contents: object;
>>>>> get
>>>>>
>>>>>
>>>>> (unsurprisingly) doesn't work right away.
>>>>>
>>>>>
>>>>> In elasticsearch it is possible to make a URI request for searching but
>>>>> it is a more limited interface than including the JSON body.
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>> Paul
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>