Closed guidoffm closed 6 years ago
Yes - it is usually done with the parse()
method. See ?reqres::Request
for the full documentation
Hello, running into the same issue. The fake Rook example works as expected:
fake_rook <- fiery::fake_request(
'http://example.com/test?id=34632&question=who+is+hadley',
content = 'This is an elaborate ruse',
headers = list(
Accept = 'application/json; text/*',
Content_Type = 'text/plain'
)
)
req <- Request$new(fake_rook)
req$parse(
txt = parse_plain(),
html = parse_html(),
json = parse_json()
)
req$body
# "This is an elaborate ruse"
However, returns empty when included in request handler: curl http://localhost:5000 -H 'application/json' -d '["Friend"]'
returns ["Hello !"]
instead of ["Hello Friend!"]
suppressMessages(library(fiery))
suppressMessages(library(reqres))
handle <- function(x) {
paste0('Hello ', x, '!')
}
app <- Fire$new(host = '0.0.0.0', port = 5000L)
app$on('request', function(server, request, ...) {
request$parse(
txt = parse_plain(),
html = parse_html(),
json = parse_json()
)
response <- request$respond()
response$status <- 200L
response$body <- handle(request$body)
response$type <- 'Application/json; charset=utf-8'
response
})
app$ignite()
Can you please give me some pointers? I can't find examples for full apps, only for Request/Response objects. Thanks!
You need to set -H "Content-Type: application/json"
instead of just -H "application/json"
So true. [slap on the forehead] Thanks.
Sent a POST request to the server with body:
On the fiery side the body is always null. Do I have to call a certain function to get the body property filled?