espresso4j / latte

Url route for Espresso

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Url route for Espresso

License:Apache License 2.0


Languages

Language:Java 100.0%