https://kotlinlang.org logo
#ktor
Title
# ktor
h

hhariri

06/29/2020, 8:06 AM
Question - what do you think about the naming for strongly-typed routes, i.e. Locations? 1. Find it straightforward and understand what it means 2. I find it confusing with HTTP Location header 3. Other (please use thread)
1️⃣ 6
2️⃣ 17
Other thoughts…
h

Hamza

06/29/2020, 8:08 AM
I know the concept is extremely powerful, but I found it confusing to understand while reading the documentation and never got around to using it. Maybe that's just me though, as I know people who use them, and love them
a

andylamax

06/29/2020, 8:40 AM
Funny, I read about them, I understood them, but never go to use them. To me it felt like too much effort for just a simple thing
m

Matteo Mirk

06/29/2020, 10:13 AM
I found it confusing since day 1. Just from the name 1. I couldn’t imagine it was a feature related to routing 2. I thought it had to do with HTTP Location header Why not just rename it to something closer to its intended usage, such as
@Route
,
@Path
or a more RESTful
@Resource
?
👍 7
c

Casey Brooks

06/29/2020, 2:29 PM
I like the idea of strongly-typed routes, but don’t care for the syntax (and the name is also not very descriptive). Using a bunch of annotations to make a route type-safe seems very un-idiomatic for Ktor, and it pulls the routing info (path) away from the
routing { }
block. I would prefer to simply add a type parameter to a normal route, rather than moving the path info into an annotation. And if this were supported, it seems like it should be part of the core routing feature, not in a separate artifact.
Copy code
routing {
    // original route
    get("/list/{name}") {
        call.respondText("Listing ${listing.name}, page ${listing.page}")
    }

    // with static type (all that's changed is the addition of the type parameter)
    get<Listing>("/list/{name}") { listing ->
        call.respondText("Listing ${listing.name}, page ${listing.page}")
    }
}
1
👍 6
r

rharter

06/29/2020, 4:36 PM
I’ve actually been working on some similar things in this space, and realized as I did that
Location
is a bit misleading since it is really describing a type-safe
Request
. For instance, I’ve been working on some type-safe template support (using freemarker), and the idea of having a type-safe
Response
gets a bit conflated with the type-safe. The name
Location
sort of hijacks the entire space while only actually serving half of the endpoint location.
4 Views