Skip to main content

Forms

Request.toForm()

Converts a application/x-www-form-urlencoded request body to an instance of the given type, with support for arrays, maps and nested objects. Field names use dot notation for nesting and square brackets for arrays/maps:

parent.children[0].name=John
departments[HR].employees[0].age=32
"/save-order" POST { request ->
val form = request.toForm<OrderForm>()
// ...
}

See the Form basics section for a worked example.

Request.queryToForm()

Same as toForm() but reads from query string parameters instead of a form-encoded body. Useful for binding rich query strings (filters, search criteria) to a typed Kotlin object.

"/search" GET { request ->
val criteria = request.queryToForm<SearchCriteria>()
// ...
}