Streamed milk Router for
espresso.
Latte allows you to route requests to certain espresso handler based on URL path pattern. It also extract variables from url spec for your handler.
Latte breaks URL into slash / separated segments.
/foomatches url/foo:foomatches a single segment in url path*foomatches rest of url segments
If you don't specify request method, it will match any incoming request for this path.
import io.github.espresso4j.espresso.*;
import io.github.espresso4j.latte.*;
var index = req -> Response.of(200).body("It works");
var fetch = req -> {
var id = Latte.extension(req).get("id");
return Response.of(200).body(String.format("Getting %s", id));
};
var notFound = req -> Response.of(404);
var app = Latte.by(Espresso.class)
.on("/", index)
.on(Request.Method.GET, "/fetch/:id", fetch)
.notFound(notFound)
.intoEspresso();See license