In section 3.6.3 Request Body of the Plumber docs there is a small example that doesn't work for me. In the bigger project I'm working on I have the same problem that whittles down to the same thing.
#' @post /user
function(req, id, name){
list(
id = id,
name = name,
raw = req$postBody
)
}
The curl
command
curl --data "id=123&name=Jennifer" "http://localhost:8000/user"
correctly returns this
{"id":["123"],"name":["Jennifer"],"raw":["id=123&name=Jennifer"]}
but the JSON formatted alternative curl
as given in the docs produces an error:
curl --data '{"id":123, "name": "Jennifer"}' "http://localhost:8000/user"
curl: (6) Could not resolve host: name
curl: (3) [globbing] unmatched close brace/bracket in column 9
{"error":["500 - Internal server error"]}
I've tried as many variants as I can find on stack overflow
and in the curl
docs but I can't solve it.
Interestingly, httr
produces the correct result:
r <- POST("http://localhost:8000/user",
body = list(id=123, name="Jennifer"),
encode = "json")
> content(r)
$`id`
$`id`[[1]]
[1] 123
$name
$name[[1]]
[1] "Jennifer"
$raw
$raw[[1]]
[1] "{\"id\":123,\"name\":\"Jennifer\"}"
So maybe I just don't understand curl
. Any help appreciated.
Personally I'd be quite happy to proceed with httr
but the intention is to run a Docker container with other devs making requests, so ideally I need to get curl
working.