https://kotlinlang.org logo
#http4k
Title
# http4k
d

dave

01/07/2021, 7:50 PM
👋🙃. @andyg All header lenses are bidi by default. Can you post a gist of what you're having trouble with
a

andyg

01/07/2021, 7:57 PM
ok I have a BiDiBodyLens like:
val myBodyLens : BiDiBodyLens<MyObjectType> = Body.auto<MyObjectType>().toLens()
and I can enforce json serialization in a response with:
myBodyLens.inject(myObject, Response(Status.OK))
but I want to extend the "contract" via Lenses so that the Response MUST have a specific header
d

dave

01/07/2021, 10:30 PM
Aha ok: it's not something we've really thought about, but I suppose you could write something generic by following the pattern from body.auto (which sets the content type and the body content). I might also have a play and see if I can come up with something:
a

andyg

01/08/2021, 5:48 AM
I wasn't aware that body.auto sets the content type... to application/json I assume? I don't see that in the docs, I even read
Q. Where is the Body.auto method defined?
and still can't find the code.
ok I did find the code, and i also see that
defaultContentType
is indeed
APPLICATION_JSON
... can I suggest adding that info to the json docs page? https://www.http4k.org/guide/modules/json/ thanks
d

dave

01/08/2021, 8:37 AM
You can certainly suggest it. And even better, the page is here for a PR to add. 😉 https://github.com/http4k/http4k/blob/master/src/docs/guide/modules/json/index.md
a

andyg

01/13/2021, 12:37 AM
Done! Happy to contribute in a (very) small way. Feel free to edit my code example.
d

dave

01/13/2021, 7:11 AM
Thanks! Will take a look this morning. 🙃