Skip to content

Instantly share code, notes, and snippets.

@s1monw1
Created October 7, 2022 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s1monw1/94edcf5a9ec6671ec41a9e0aad6a9021 to your computer and use it in GitHub Desktop.
Save s1monw1/94edcf5a9ec6671ec41a9e0aad6a9021 to your computer and use it in GitHub Desktop.
[...]
import org.http4k.format.Jackson.auto
class PersonHandlerProvider(private val service: PersonService) {
private val personLens: BiDiBodyLens<Person> = Body.auto<Person>().toLens()
private val personListLens: BiDiBodyLens<List<Person>> = Body.auto<List<Person>>().toLens()
fun getAllHandler(): HttpHandler = {
Response(OK).with(
personListLens of service.findAll()
)
}
fun postHandler(): HttpHandler = { req ->
val personToAdd = personLens.extract(req)
service.add(personToAdd)
Response(OK)
}
//...more
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment