Spark Framework

There's a neat little framework I've used recently called Spark. It is yet another Java HTTP framework, but it's a very small and simple one.

I have written about Dropwizard in the past which is also a small (compared to say, Spring) web framework, but Spark takes it to another level.

Here is a code snippet taken from their site:

import static spark.Spark.*;

public class HelloWorld { public static void main(String[] args) { get("/hello", (req, res) -> "Hello World"); } }

That is all (ignoring Maven config) that's needed to start serving HTTP requests from the JVM.

I've not had the opportunity to use Spark in anything resembling a production environment so I cannot vouch for its reliability there. However I have used it for small projects and it's been great doing zero setup before writing code that has an impact on the API's output.

Compare this to the equivalent endpoint using Express:

app.get('/', function (req, res) {
  res.send('Hello World!');

Uncanny, right? The Java sure as shit wouldn't have looked like that a few years ago...

I know of a few JavaScripters who would like to learn Java but find its learning curve off-putting. Spark may offer a foot in the door by helping to lower that learning curve. It provides a natural application structure far more familiar to those who've used Express in the past than any other framework I've seen so far.

They have easy to follow documentation on both setting up Maven and Spark itself, if you're interested.

Thanks for reading!