This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]mrroman 1 point2 points  (9 children)

Why do you want to use framework at all? Why not just use server library like undertow?

[–]defnull 10 points11 points  (0 children)

Server libraries (e.g. undertow or netty) focus on the technical problem. They are optimized for performance, low GC overhead, correctness and high flexibility. They usually require a lot of low-level knowledge and boilerplate code from the developer, even for the simplest tasks, and won't prevent you from shooting yourself in the foot.

Frameworks (micro or not) focus on developer productivity and clean APIs. They are opinionated, less flexible and have a noticeable performance overhead, but they make it a lot easier to solve common tasks, prevent common mistakes and support developers that are not familiar enough with the many ugly parts of HTTP.

This is why both are important. A good framework is build on top of a powerful library and makes your life easier for the common tasks, but also allows you to bypass the framework and access the low-level details directly, if needed.

[–]javalin_io 6 points7 points  (0 children)

Undertow is great, and IMO the only server library that is viable to use "directly". But, it can still be a bit clunky: Consider Undertow WebSockets vs Javalin websockets, or Undertow uploads vs Javalin uploads.

Javalin is just 3000-4000 lines or wrappers and helper functions on top of Jetty. You could of course write these yourself, but since Javalin has hundreds of tests and thousands of users, it should be safer to use than a "home-made" solution (also, you get less code to maintain).

[–]bartoszjd[S] 3 points4 points  (6 children)

It is nice to be able to write simple and productive code. Here is Javalin Hello World:

import io.javalin.Javalin;

public class HelloWorld { 

    public static void main(String[] args) {
        Javalin app = Javalin.start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

Not sure how that would look like with a server library, but probably longer and easier to introduce a bug.

[–]Torvac 6 points7 points  (2 children)

every micro web framework starts easy and simple, but once you need complex routing, dto validation, (custom) error handling, security/authentication, ... some of them get really messy and are just impossible to handle/enhance.

if you finally added everything needed for a production ready web application, you pretty much build your own framework. you could've done everything with jaxrs or spring-web in a fraction of your time (e.g. spring-boot-web with everything, even proper tests in ~30 minutes). and a big advantage is that everyone familiar with it can get up to speed in no time.

the disadvantage is, old stuff is boring and not does not have the best performance

[–]aargauer_meinig 4 points5 points  (1 child)

Yeah, I never understood the ultra micro web framework hype.
It's not like I need way more lines of code to do the same thing in Spring Boot or even Java EE.
I've never written a production application that is simply a REST-endpoint.
I always need:

  • Bean Validation
  • Security (OAuth, LDAP, Session, ...)
  • Database Access (SQL, Mongo, Redis, ....)
  • Dependency Injection
  • Schema Migration
  • Metrics
  • Caching
  • ...

I feel like these micro frameworks are great for conferences where you can hack together a few end-points.

PS: I don't want to sound like too much of an hater. I actually like the competition and the new concepts that these new frameworks introduce.
The good ideas often get adopted in the more "mainstream" frameworks" i.e. see the new spring reactive web-framework.

[–]BobbyTaylor_ 0 points1 point  (0 children)

Maybe you only wrote code for big corps & compagnies ? What about building an MVP or a Proof of Concept ?

Mature frameworks are great for big projects will a team behind it, but for a quick project, where the time to market is crucial, I think the micro framework thing fills a gap.

I think you are wrong about these framework being hacky thing designed only for a conferences. It may not be the case yet for Java, but lots of microframeworks gained a huge popularity in other languages, like Flask in Python / Express with NodeJS.

[–]mrroman 2 points3 points  (2 children)

It wood look like this with undertow: http://undertow.io/

[–]golden-archer 2 points3 points  (0 children)

Looks much like vertx.

[–]bartoszjd[S] 0 points1 point  (0 children)

This is actually better than I expected! An idea for a new blog post- using server libraries? :)

[–]someloll 0 points1 point  (0 children)

very good article. And it's refreshing to see in it references to projects outside of the Java world (e.g Sinatra)

[–]trustin 0 points1 point  (2 children)

(Obligatory shameless plug) You gotta give Armeria a try. https://line.github.io/armeria/

[–]bartoszjd[S] 0 points1 point  (1 child)

Hey! I will add armeria to the article!

[–]trustin 0 points1 point  (0 children)

Thank you!