-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vert.x Web DSL routing #91
Comments
do you have an example on how you think it should look like? Also, should it be part of the |
I am not a Kotlin expert and I leave that up to the community to come up with the best API that makes sense. It should be custom code part of |
cool, I'm curious to try it, even just to give inspiration to others |
I did something similar for one of my own Vert.x+Kotlin projects. Will try to come up with a proposal in the next week or two. |
it would be great to involve also the Kotlin Vert.x slack channel for feedback :-) |
A proper coroutine handler would be great, supporting suspending functions. Workaround currently is to write an extension function. route("a") { // matches first segment with the value "a"
route("b") { // matches second segment with the value "b"
get {…} // matches GET verb, and installs a handler
post {…} // matches POST verb, and installs a handler
}
} |
I cannot stress enough the importance of coroutine-enabled |
@JohannesLichtenberger this is quite an interesting problem. Since |
Currently I'm using this extension function: private fun Route.coroutineHandler(fn: suspend (RoutingContext) -> Unit): Route {
return handler { ctx ->
launch(ctx.vertx().dispatcher()) {
try {
fn(ctx)
} catch (e: Exception) {
ctx.fail(e)
}
}
}
} So, this doesn't work anymore? But sounds great, implementing |
It still works in 3.6 as long as the extension is defined inside of a |
Hello All, I am currently working on a dsl for our internal use and I wanted to show it off a bit determine whether it would be something good to give back to the the vertx project. fun main(): Unit {
val vertx: Vertx = Vertx.vertx();
server(vertx) {
router("/v1") {
//Create a route at localhost:8080/v1/hello
getAwait("hello") {
//this is a coroutine handler
delay(500)
it.response().end(jsonObjectOf("hello" to "world").toBuffer())
}
}
}.listen(8080)
} Its lightly inspired based on the dsl for koin which we use for dependency injection. If interested I can start looking at getting the dsl code together for contribution. |
that would be great @Tim-Britton |
Could we get rid of the "Await" method postfix? :-) I know it's otherwise for the Vert.x calls auto generated, but then it would be in-line with the Ktor routes, I think. |
I think if we get rid of it, it would create ambiguities sometimes.
… On 28 Aug 2019, at 13:08, Johannes Lichtenberger ***@***.***> wrote:
Could we get rid of the "Await" method postfix? :-) I know it's otherwise for the Vert.x calls auto generated, but then it would be in-line with the Ktor routes, I think.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#91?email_source=notifications&email_token=AABXDCQIR2E3EI3MXRCWOB3QGZMCHA5CNFSM4GDB4JB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5KX4UY#issuecomment-525696595>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AABXDCQA3FXJMNDL6B33LR3QGZMCHANCNFSM4GDB4JBQ>.
|
Ah okay..., but looks great :-) |
we also discussed that with vertx 4, the new Future API should improve coroutines API |
@JohannesLichtenberger I use the await postfix to inform the user that they are getting a coroutine context rather than a standard handler context. @vietj we'll start moving in that direction then! The implementation details require delegation similar to what is used with the rx versions of the vertx classes. I'll try to block out some time to get this started! |
The new Kotlin stack integration in 3.6 allows to have custom Kotlin DSL's.
It would be great to have a Kotlin DSL for Vert.x Web that makes templating more Kotlin-ish.
The text was updated successfully, but these errors were encountered: