Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This was an interesting read for a Java / JVM language developer that has recently begun learning and using Rust in personal projects.I was curious how the magic was working begind the scenes. In the Java world, our most popular framework (Spring Boot) takes Magic to another level, since Java allows reflection, lots of magic is possible.


Luckily, there are saner alternatives on the JVM. If you read at "Your server as a function" paper from Twitter, you'll see that the composing of middleware and simple handler functions can be used to develop powerful stacks which are a doddle to write, reason about and test.

The SaaF design was used to design Finagle (Scala), and then it inspired http4k (Kotlin). There may be more that I'm not aware of. These libraries are often described as micro-frameworks - but this is misleading - it is only because the core is very small and can be easily extended by bolt-on modules.


The JDK has a server-as-a-function-ish web server built in (and has done for years):

https://docs.oracle.com/en/java/javase/17/docs/api/jdk.https...

Because HttpHandler is a functional interface, you can write lambdas for it. Here is a little outline of a server:

https://gist.github.com/tomwhoiscontrary/b4888b86057c74a636c...

Sadly, Filter is not a functional interface, so it's much clunkier. It's also not really clear why you would use a filter when you can do function composition; i suspect they added filters because previous Java web frameworks had them.


What does SaaF mean?

Googling gave me a bunch of buzzword marketing sites and scared me off.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: