As explained in my previous blog post, I had been struggling to build authentication with an interface that I liked. It was clear to me that if I could solve the route grouping problem, then I would be half way to solving the authentication approach. So that's what I've been working on today.
I was getting nowhere, and out of desperation and curiousity I asked AI text generator ChatGPT if it could write me a simple HTTP router in Kotlin. It did. So I asked it if it could support nested routes, and gave it an example of what I meant.
It did.
And from that very basic example from an AI, I build a new "Simple" router to help me understand how it worked and why I had been struggling. Once the simple router was working, nested groups and all, I was able to see what changes I needed to make to my real AWS Lambda router classes to make it work the way I want. So now, it works. I can write code like this:
val router = lambdaRouter {
get("/", rootController::getRoute)
group("/users") {
get("/", userController::getAllUsers)
post("/new", userController::addNewUser)
}
}
I have kept the SimpleRouter class and test, as it will help me with other experiments without needing to deal with the full complexity of the full Lambda router. I have deployed and tested this, and feel relieved that I have made it work - with a little help from an AI!
Prev: Starting the web front-end Next: Authorization Complete, CORS pain