I would like like to create a routes in programati...
# ktor
t
I would like like to create a routes in programatic way instead of using dsl. Is there any sample available on this?
c
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
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
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
It should be. Ultimately route, get, post, are all functions that are just adding route entries.
t
cool. thanks for the tip. I will try it.