Espresso
A lightweight HTTP library for Java inspired by Echo
For as long as I have been programming in the Java community, the defacto way to create Web APIs and REST services in Java has been the Spring framework and ecosystem .
Although this project is pretty much the standard way of creating and maintaining complex applications, for simple web servers, it is a bit too much. looking for an alternative solutions in Java’s standard library or third party libraries didn’t satisfy what I was looking for, so figuring that it would a fun little challenge, I created this project.
Introducing Espresso, a lightweight HTTP library for Java inspired by the Echo Web Framework . In this project you can create a simple web server in a few lines of code:
void main(String[] args) {
Espresso espresso = new Espresso(JettyOptions.defaultOps());
espresso.get("hello", (request, response) -> {
response.text(HttpStatus.OK, "Hello World");
});
espresso.start();
}And with this we have an HTTP server!!!
Motivation
I began this project as a practice I’ve been meaning to do since the beginning of my college, Writing an HTTP webserver from scratch. Also, knee-deep in spring ecosystem, I wanted to see if I could create something more light weight; something that didn’t used reflection, annotations and magic
So I got to work, opening a socket, reading the stream, parsing the data, calling the required functions and writing to the socket, the standard stuff. But, that wasn’t enough so I started to write a session manager, a Trie structure to hold the registered URLs and mapping from URLs to Handlers.As the project grow and I started to add new features to it, I realized that trying to optimize the socket and handling everything would become tedious a task and after some searching I choose Jetty as the underlying HTTP server implementation.
With changing to Jetty came a great refactor, with refactor new ideas and with new ideas came new knowledge and understanding. this project taught me many things and I hope people will enjoy using it.
