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 bodyContent-Type →application/octet-stream
s4nchez
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 wireResponse(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.octet-stream
seems like an odd default.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