Hi everyone! Not sure if this is the right place,...
# server
c
Hi everyone! Not sure if this is the right place, but it was the best that I found for the question I’m planning to start a new backend project using Kotlin and I was wondering about the options of web framework to use. I know Spring is a pretty solid one, but maybe there are others more suited for Kotlin specific applications. So, what web frameworks do you guys recommend?
j
Micronaut
p
Both http4k and ktor are kotlin-first and are worth taking a look at.
K 6
c
Second that. Ktor is very kotlinesque (and could still be considered a framework). Http4k is a bit more low level imho, but still a very good candidate. It depends also on your tolerance for annotation-based magic. SpringBoot has a lot of it (like @AutoWired). I personally do not like it much: I feel it is a band-aid on Java's inherent verbosity, something we can do better with Kotlin.
7
r
Spring gives you a lot of advanced stuff out of the box. Most of other frameworks are much simpler. You can also check Jooby, Javalin, Vert.x and Quarkus.
t
It also kinda depends how many enterprise features you need. If you really only need a webserver Javalin is great, but once you start wanting things like metrics/security/integration with popular libs then you will need something more. I only have experience with jjavalin, spring and micronaut, both work but the problem with micronaut is a big lack of documentation (the official one is ok, but doesnt mention everything, and stackoverflow doesnt have that many questions answered), so as long as you want to do very standard things its ok, otherwise i would not go for micronaut. No experience with quarkus myself, but some collegues of mine went back to spring. I hear good things about Ktor though
d
I would recommend ktor, its an amazing fraemwork!
K 2
c
@Ties is you "only need a webserver" and intend to use it with Kotlin, I think http4k and Ktor are better options. Ktor seems to be a lot more active and has about 2x the number of github stars, compared to Javalin. Javalin seems to be Jetty only, where Ktor allows you to use one of many server backends (https://github.com/ktorio/ktor/tree/main/ktor-server ).
a
Javalin isn't as powerful as the other options presented, but imo, it's the easiest to get started with. That should at least be taken into consideration.
2
c
Thank you guys I really liked the Ktor and Javalin APIs I’m really tempted to use Ktor because of its kotlin-first API Although the project I’m gonna to work with has the potential to grow quite a lot and because of that I’m thinking it’ll be better to use SpringBoot due to it robustiveness and community support
a
All of the options suggested here are fully capable of handling any production load you want to throw at them. Don't choose what you think is the most "enterprise"; choose which one you like best.
3
d
Incredibly biased although I am 😉, I think it's also important to consider testing when it comes to your making your choice. ⚠️ Sales pitch incoming ⚠️ Nothing else comes close to http4k in its attitude to throughly being able to shift as much testing left as possible, and writing portable tests that can be used against an on memory app, a locally running server or a remote one with a single line of code. It's even designed so you can throw away http4k away and keep your tests in place ! Testing http4k requires zero testing infrastructure - no "test harnesses", no complex component lifecycles, and definitely no magic maps of beans! 🙃. You can even fully unit test OAuth redirections flows and websockets entirely in memory with no server! Composing applications out of functions is a hugely underappreciated technique in terms of the power it gives you with just a couple of simple patterns. There are more advanced topics to be sure (eg. lenses), but compared to the magic of annotations it's really just function composition and you can see all the code and step through at every point if required. Are you going to be able to copy-paste code from stack overflow? Definitely not as much - the direct style can be quite alien if you're just used to being spoonfed magic, but for people with experience in other languages, it's actually more natural. Http4k contains ~65 modules covering everything you might need from Json/xml/JSON RPC to graphql to typesafe configuration to open API generation to OAuth security to websockets/SSE to opentelemetry to templating to advanced testing (matcher libraries/approval testing/webdriver/service virtualization - and the upcoming diagram generation). And v5 will support about 20 backends including 6 serverless platforms. And did I mention the zero-reflection cloud client library which can be used instead of the heavyweight aws SDK and comes with fake servers that can be used to test AWS services in memory without the need for localstack? Or that we've just added an SDK to allow you to simply create and test fully authed OpenAI plugins , along with a fake OpenAI server to plug them into or test against- which can also be used to "generate" chat responses or images without using up valuable tokens. Yes we've been busy. 🤣 Now of course, noone ever got fired for "choosing the industry standard", but then I don't personally think people should aspire to be "industry standard" engineers. 😉 ⚠️*end sales pitch* ⚠️ Regardless of which way you're leaning, I'd encourage you to scratch below the surface of your options to make a more informed decision to see what really makes them tick. Maybe write a couple of spikes to compare and contrast?
🙌 4
plus1 2
s
+1 For Vertx
1
j
Just to complete the above options, you can also give a try to hexagonkt.com whose spirit is to be a Javalin like toolkit taking advantage of the Kotlin features
1
c
Thank you @Andrew O'Hara for the feedback, I’ll investigate a little further to see if Ktor support the use cases of my application, if yes, then I’ll definitely reconsider my choice
And thank you @dave for the detailed explanation over the advantages of http4k, you got me curious kkkk I’m going to create a POC with http4k to see it working in practice
d
Hope it works out for you @carlos ! Be sure to pop into #http4k if you want to ask any questions about it 🙂
✌️ 1
s
The perfect web framework would be scalable ... also observable, magicless, with plenty of out-of-the-box integrations.
2
l
You gonna be extremely surprised in how good
Quarkus
is, even not being the most kotlin-focused framework. I like
ktor
but it lacks in terms of out-of-the-box features, so it depends a lot on what do you need. And you are kinda confined to use
Exposed
for persistence, that's very behind any other persistence solution like
spring-data-jdbc/r2dbc/jpa
,
micronaut-data
,
hibernate
. Also consider if you need out-of-the-box support for cloud providers etc.
http4k
also deserves a look.
a
Ktor (like Http4k and Javalin) doesn't impose any restrictions on your persistence layer.
1
l
also don't provide any out-of-the-box integration.
a
Yes, that's the one of the main differences between a framework and library.
s
The perfect web framework is a library
💯 1
j
And instead having a lot of integrations, I see more value in making easy to write your own... so you don't depend on others schedules
Also, probably there is no such thing as the perfect web server toolkit/framework, it depends on the use cases... that's why there are so many, here I suppose the focus is on the more mainstream/balanced ones
l
Yes, hundred of thousands companies writing the same integration code for the same components… that sounds really great.
j
Frameworks not providing integrations doesn't mean everyone has to code one themselves. Focusing on easy to code integrations would lead to many different integrations rather than an official one. And people would have more options to pick from, or roll their own specific to their needs.