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
[routing] Replace consumer with SAM interface with receiver #2049
[routing] Replace consumer with SAM interface with receiver #2049
Conversation
So this will look identical to using the Apibuilder from Kotlin.. And we'll introduce a split in syntax between Java and Kotlin.. Why not use the Apibuilder instead ? |
We could also provide SAM with receiver as a second mount variant 🤔 I don't like ApiBuilder (static imports, context & building routes via nested groups) + that's simply a bit different approach. Also, I'm mainly looking at it from the perspective of 4 other routing implementations as I'm in a process of porting all of them to the new API. |
Can you add some Java API compile tests? In case some of us touch this and mess it up. |
Actually, there are some tests in Java that use this API, but like I said, this change does not affect it as this SAM interface with receiver looks basically the same as Consumer in Java. E.g. this one: javalin/javalin/src/test/java/io/javalin/examples/HelloWorldAuth.java Lines 31 to 39 in 435c896
|
This still introduces a split in API for Java and Kotlin users, which is something we've been trying very hard to avoid so far in Javalin. The fact that it looks like the statically imported ApiBuilder is also a major downside IMO. We need to find some sort of solution that both looks and works the same from both languages, or it needs to live in an extension artifact. |
Because this feature is only dedicated for Kotlin users, I've replaced it with an extension function. Thanks to that, default mount function work the same as in Java, but there's still an opt-in possibility to use a DSL in kt - that's mainly useful in 3rd party routing impls. Quick note: I had to use a hidden functionality of kotlin std ( |
Making it an extension function doesn't really solve the main issue though, you still have something that looks and acts like the |
I can define this extension function on my side, but I still need |
So now this improvement is possible on my side, but it's not affecting public API in Javalin core. Do you think you're fine with this change at this point? 🤔 |
Yes, thank you 🙏 |
|
Basically, instead of:
We'll be using
No changes for Java users.