My question is about the big picture behind routing functionality in Ktor; and scalability when it comes to design an API with large number of routes.
If I create an app like this:
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
fun Application.routingExample() {
intercept(ApplicationCallPipeline.Call){
if (call.request.uri == "/") call.respondText("User call for /")
}
}
fun main(args: Array<String>) {
embeddedServer(Netty, 8080, watchPaths = listOf("Routing"), module = Application::routingExample).start()
}
Which is ok if I have an api/app with low number of routes. However in what style I should scale this approach for large number of routes (e.g., 30 routes and controller functions).
I would have a number of choices:
A large routing function: I would have a large Application.routingExample
function that would hold all the routes, so I don't need to update the main.
A large main function: Would have a large function that would hold the calls to different smaller functions; but it would be repetitive; as for an API I want to serve them in the same port.
So my question is about the coding style: is there a way to to factorize the routing controller relationship?