Skip to content

espresso4j/latte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latte

Maven Central Javadocs Travis (.org) GitHub Liberapay patrons

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.

Usage

Latte breaks URL into slash / separated segments.

  • /foo matches url /foo
  • :foo matches a single segment in url path
  • *foo matches 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();

License

See license