danneu / kog

🌶 A simple Kotlin web framework inspired by Clojure's Ring.
43 stars 4 forks source link

[Router] Parse url /:params #1

Closed danneu closed 7 years ago

danneu commented 7 years ago

This is a familiar way to parameterize segments of the route url:

get("/users/:id", fun(request: Request): Response {
    val user = database.getUser(request.params.get(":id"))
    user ?: return Response(Status.notFound)
    return Response().text("Hello, ${user.name}")
})

Just want something quick/dirty/working to start with.

danneu commented 7 years ago

Started implementing this in https://github.com/danneu/kog/blob/183267b234f94d1eb49e6498ecebc3c7050503f2/src/main/kotlin/com/danneu/kog/Router2.kt which will eventually replace Router.kt once it catches up.

danneu commented 7 years ago

The new type-safe router is the best url-param parser, yet: https://github.com/danneu/kog/commit/143f929e22cd1c998bb375ba530f2de476c5fdfd