Is there any way to automatically add defined rout...
# ktor
i
Is there any way to automatically add defined routes at compile-time (or runtime) without having to explicitly add them in the application module definition? Not only does it get tedious, it's also error prone if you forget to register a defined route. I assume it should be possible with code-generation or annotation processing such as kapt, but I'm wondering if anyone has already done something like this?
b
Have you tried ktor locations feature?
i
@Big Chungus The documentation says it's deprecated and instead points to
Resources
plugin. But from what I gathered from reading the
Resources
documentation, I'd have to put all routes in a certain hierarchy as inner/nested classes. Afaik Kotlin has no way to externally create a nested class, right? That means that all routes in a single hierarchy would then need to be defined in a single file 😞
a
You don’t have to use nested classes to define resources although you need to define a property in a child resource class to a parent resource class https://ktor.io/docs/type-safe-routing.html#resource_nested.