Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 655 Bytes

README.md

File metadata and controls

27 lines (20 loc) · 655 Bytes

Type-Safe request objects

Installation

implementation("io.github.turchenkoalex:kotlet-typesafe:1.0.0")

Configuration

Few helpful methods for parsing request query parameters: receivePath and receiveQuery.

@Serializable
data class UserPath(val name: String)

@Serializable
data class UserQuery(val age: Int, val city: String)

post("/user/{name?}") { call ->
    // /user/John?age=30&city=New York
    val user = call.receivePath<UserPath>() // UserPath(name = "John")
    val query = call.receiveQuery<UserQuery>() // UserQuery(age = 30, city = "New York")
    update(user, query)
    call.respondJson(user)
}