https://kotlinlang.org logo
Title
t

Thiyagu

06/02/2020, 6:35 PM
I would like like to create a routes in programatic way instead of using dsl. Is there any sample available on this?
c

Casey Brooks

06/02/2020, 6:38 PM
The DSL is just normal Kotlin code, you can do any programatic logic directly in the DSL! I’ve loaded routes from JSON before, and it works great
h

hhariri

06/02/2020, 6:57 PM
As Casey mentions, thE DSL is essentially just calling routing functions that add the routes. You can essentially do what you want. However, what do you mean with pragmatic approach?
t

Thiyagu

06/02/2020, 7:16 PM
I have dsl like this now, route("/task") { withRole("Admin") { post { //process here } } withRole("user") { put { //process here } } get { //process here } } Instead of writing DSL like this, I would like to write method like below and then will add the routeSelector based on the
role
value passed buildRoute(path:String, role:Role?, handler: PipelineInterceptor<Unit, ApplicationCall>). Is it possible?
h

hhariri

06/02/2020, 8:09 PM
It should be. Ultimately route, get, post, are all functions that are just adding route entries.
t

Thiyagu

06/03/2020, 7:09 AM
cool. thanks for the tip. I will try it.