hi all. Is it possible to write a lens that extrac...
# http4k
n
hi all. Is it possible to write a lens that extracts an instance of a data class from an HTML form that contains multiple fields? I have
data class Session(val id: Int? = null, val date: LocalDate, val student: Student, val amount: Int)
and all the fields for this appear in the form, but I can't work out how to construct a lens to extract one of these. Denton showed me how to create a lens to extract a data class from a single form field, e.g.
Copy code
private val studentLens = FormField.map { Student(name = it) }.required("studentName")
private val studentFormBody = Body.webForm(Validator.Strict, studentLens).toLens()
but obviously having multiple fields is more complicated. I looked through the cookbook on the http4k website, but didn't see anything that helped. I looked at the
BodyLens
class, but wasn't really sure if that's what one's supposed to use in that case (or how to use it, tbh).