hi. Can somebody please tell me what’re the benefi...
# ktor
e
hi. Can somebody please tell me what’re the benefits of using type-safe routing? The only one I can think of is behind-the-scene mapping of query and path params to the resource fields, so you can write
Copy code
resource.id
instead of
Copy code
call.parameters["id"]
c
You can write
Copy code
resource.someInt
instead of
Copy code
call.parameters["someInt"]?.run {
    call.respondText("Missing parameter 'someInt'", HttpStatusCode.UNPROCESSABLE_ENTITY)
    return@route
}.toIntOrNull()?.run {
    call.respondText("Parameter 'someInt' should be an integer", HttpStatusCode.UNPROCESSABLE_ENTITY)
    return@route
}
Also, you can use the same classes client-side, so refactoring a query parameter in IDEA changes it on the entire stack without having to manually search through all usages manually. It's a bit limited however because only the request is typesafe (query params + body) and not the response.
💡 2
e
Gotcha. Thank you