-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for body in GET requests #675
Comments
I miss exactly this feature/behaviour. |
I tried to get around this issue by using the VERB() function, specifying verb="GET" and supplying data for a body (see below for a non-reproducible query). Unfortunately server response always indicates a missing body from the request.
|
Update regarding ElasticSearch requests: I was able to do the same request using POST. |
I just spent 45 minutes trying to talk to Elastic via httr. And already thought I was infinitely stupid and despaired of myself. :D Thanks so much for the clarification. It would be really cool if GET would support body too. |
Hello, is there any update on GET supporting body? Thanks! |
I don't use R much anymore, but I just noticed there is a new |
Thanks @pieterjongsma, I also had a look at httr2, but it also seems to not support body when using the GET function. |
I have had success using AWS opensearch with a GET with a JSON body by calling
|
Content in a
https://www.rfc-editor.org/rfc/rfc9110#section-9.3.1-6 So that means you'll always need to set a custom method like @MrFlick suggested, or with httr2: library(httr2)
request("http://httpbin.org/post") |>
req_body_form(a = 1, a = 2, a = 3) |>
req_method("GET") |>
req_dry_run()
#> GET /post HTTP/1.1
#> Host: httpbin.org
#> User-Agent: httr2/0.2.3.9000 r-curl/5.1.0 libcurl/8.1.2
#> Accept: */*
#> Accept-Encoding: deflate, gzip
#> Content-Type: application/x-www-form-urlencoded
#> Content-Length: 11
#>
#> a=1&a=2&a=3 Created on 2023-10-31 with reprex v2.0.2 |
I feel the HTTP spec is a bit murky regarding this topic, but as far as I can tell, including a body with a GET request is allowed:
One example of an API that accepts (json) bodies on GET requests is Elasticsearch. Possibly because Elastic felt GET is more appropriate for a non-mutating request.
Currently, httr seems to simply not include specified bodies in GET requests. As such, it is currently not possible to use httr for all endpoints in Elasticsearch.
I'd be happy to attempt and make a PR for this change. Just want to make sure this is something that would be accepted.
The text was updated successfully, but these errors were encountered: