Nezteb
04/22/2019, 9:31 PM.body
, not .with
, but how can I convert the request to JSON? I could use a Jackson mapper manually, but I assume HTTP4k has a built-in way to do it
fun getRequestAsJson(): HttpHandler {
return {
Response(OK).body(it)
}
}
s4nchez
04/22/2019, 9:33 PMNezteb
04/22/2019, 9:36 PMjacksonMapper.readValue(request)
and put it in the response bodyNezteb
04/22/2019, 10:02 PMContent-Type →application/octet-stream
Nezteb
04/22/2019, 10:03 PMs4nchez
04/22/2019, 10:44 PMResponse(OK).body(request.toString())
. The string versions of request and response are similar to what is sent over the wires4nchez
04/22/2019, 10:47 PMResponse(OK).header("content-type", "application/json")
or, using Lens via Response(OK).with(Header.CONTENT_TYPE of ContentType.APPLICATION_JSON
Nezteb
04/22/2019, 10:47 PMfun health(): HttpHandler {
return {
Response(OK).body("I'm healthy!")
}
}
the header here defaults to octet-stream
every time.Nezteb
04/22/2019, 10:48 PMoctet-stream
seems like an odd defaultNezteb
04/22/2019, 10:49 PM.with(Header...
bit, thanks~s4nchez
04/22/2019, 10:49 PMoctet-stream
is not our default. It's probably the backend you're using or what the browser or client assumes if the server sends none.Nezteb
04/22/2019, 10:50 PM