How hard is it to start a Web Server?
For Code-Story coding challenge, Jean-Laurent and I have been trying to work with existing web or rest stacks. None was as simple as we wished. Yes you hear me well: none of the bazillions existing web framework was simple enough.
The most simple use case is:
We are currently working on our own stack developed with Java 8 : Code-Story Http. The name is the worst we could come up with and it might change if we ever feel the urge to do so.
With this simple stack, here’s how we start a Web server:
Maven configuration:
<dependency>
<groupId>net.code-story</groupId>
<artifactId>http</artifactId>
<version>1.31</version>
</dependency>
Java code:
import net.codestory.http.*;
public class StartAWebServer {
public static void main(String[] args) {
new WebServer().start();
}
}
That was hard!
With this code you get a fully functional web server running on port 8080 ,serving files under app folder as static assets. It is able to convert on the fly, server-side, coffee to js, markdown to html, asciidoc to html, less to css. It has a server-side templating engine based on HandleBars. It handles most of the features Jekyll would provide like layouts, includes, yaml based configuration…
If this can be done with so few lines of code, what can be done with the more line? We used java 8 and Nashorn a lot to make our stack easy to use, yet powerful.
If you are interested, read the documentation (still under construction)
I’ll talk more about this web server in the upcoming days.