Hi, this is about routing. Having spent a few year...
# ktor
h
Hi, this is about routing. Having spent a few years with the Play framework before moving to kotlin, I have several times found myself longing for the very compact and clear routes definition in Play. I find it gives me a very good overview over a server to see all its endpoints in one place. So I now created a code generator (using KSP) that will take a routes file in the Play framework style and generate code to call my different request handlers: https://github.com/hallyhaa/ktor-routes-codegen. I have discussed this earlier with @Thiago (here). And also think this simple code-generating annotation could be facilitating migrations from Play framework to Ktor (wanted to tip Sergey Mashkov about this, but his account here is deactivated). There is a short example of how to use this here: https://github.com/hallyhaa/routes-file-example Does anyone think this is practical?
🎉 1
p
Sounds good but what about those controllers with constructor arguments?
h
You would prefer not to have those arguments since you may extract the values yourself in the controller? Do you mean they complicate stuff?
p
So basically it is just to generate no argument controllers. I asked in case I wanted to inject dependencies in my controller.
h
Oh, sorry, I see what you mean now. Well, I haven't thought of that at all, so as the code looks now, you can only get no-argument constructed controllers.
👍 1
p
Is ok, you want to be similar to the play framework. Scala has this feature of implicit parameters and you could use that to do method injection. Kotlin promotes more construction injection. Explicitly in the class constructor. Might make the difference. I prefer to declare the controllers routes with an annotation in the controller class like in Spring.
h
The primary goal of this code is to provide the ability to define all the endpoints/routes in the very compact routes file format.
🆗 2