Does htt4k have any support for generating HTML re...
# http4k
m
Does htt4k have any support for generating HTML responses with kotlinx-html?
s
What kind of support would you expect for that? As kotlin-html allows generating the HTML as string, one can simply inject that to the body response.
We could perhaps extend the templating abstraction to use it, but I wonder what's to be gained given it's all Kotlin anyway.
m
It would be nice to have a lens for it, so that you get proper Content-Type header and possibly make use of streaming.
You can do this:
Copy code
val htmlLens =
        Body.string(TEXT_HTML).map<String>({ throw UnsupportedOperationException("Cannot parse") }, { it }).toLens()

Response(OK).with(htmlLens of createHTML().div { +"some text" })
But it would be nice to utilize the streaming to
Appendable
.
A template abstraction would probably be overkill.
But it seems like the template abstraction does not allow streaming either, even though at least some of the template engines support that.
It would be nice to factor out the
createHTML()
part into a lens, but not sure how do to that since it returns a
TagConsumer
you are supposed to fire events on.