danneu / kog

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

Support java.time formatters in Router handlers #4

Open danneu opened 7 years ago

danneu commented 7 years ago

It would be nice to have type-safe routes that only match if the provided formatter can parse the param.

e.g. This would be cool:

val router = Router {
    get("/when/<start>/<end>", fun(start: kog.ZonedDateTime("yyyy MM DD Z")) = ...)
    get("/when/<start>/<end>", fun(start: kog.ZonedDateTime(DateTimeFormatter.ISO_INSTANT)) = ...)
}

Impl idea: wrap java.time constructs myself so that the user can specify kog.ZonedDateTime(Formatter) like above and then start.get() to unwrap them back into java.time constructs. Or instead of wrapping construct, provide an interface that user can extend.

Basically need user to provide the destination class and a formatter that attempts to parse param into that object.

Reminder: http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html

A Hex matcher would be nice, too. e.g. hashes.

Consider a way to support arbitrary loaders like get("/users/<id>", fun(user: User) = ...).