<@U096EGZ6U> That seems closer to my use case, but...
# ktor
d
@cy That seems closer to my use case, but I don't see how I would use other response types and status codes... my problem is that the client program has a funny and inconsistent api, so I want to abstract things to be able to adapt. I would need to pass the call to an intermediary handler function that translates the controller results into by calling various responseXXX() methods on ApplicationCall
d
Can you show a sample of what would you do on vertx?
k
I'm curious how you got this to work in vertx as well
d
I'll try posting it later on today..
👌 1
Usage is:
Copy code
post("/crm/pay_security_plan").coHandler {
				registrationPaymentController.paySecurity(toPaymentRequest())
			}
d
And can you put a small snippet showing how do you use it vs how would normally do routing?
ok
so you are somehow decorating the route
d
The return value from the controller is caught by coHandler and returned
And the request params are processed in the Vert.x layer to transform them for the business logic layer like this:
Copy code
fun RoutingContext.toPaymentRequest(): PaymentRequest =
		Klaxon().parse(bodyAsString)!!
Which is a simple example, but there could be request params and headers too...
That way business logic is seperate from the framework, a sort of Clean Architecture pattern...
I got it based on Sergey's answer: https://gist.github.com/dave08/b6df4b5d18ca9dff5530fa2d35a99f82 simple smile
Just a bit more bulky than Vert.x since I have to implement this for each request type...
d
That's another possibilty, but how does this work :`fun Route.get(path: String): Route = route(path, HttpMethod.Get) { /* What goes here? */ }`? And how does coHandler come off it?
d
That should be empty
it is just a callback that is called with the route, to create more subroutes or to put a handler
you can inline it too, but I wanted to show how to keep the same exact syntax you had with vertx Edit, changed to the equivalent to make it clearer (those methods in addition to calling the lambda with the sub-route as receiver, it also returns the created sub-route node, so you can add a handler to it later):
Copy code
@ContextDsl fun Route.get(path: String): Route = get(path) { } // Note: Lambda intentionally empty
@ContextDsl fun <http://Route.post|Route.post>(path: String): Route = post(path) { } // Note: Lambda intentionally empty
👍🏼 1