Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Latest commit

 

History

History
46 lines (34 loc) · 1.48 KB

routing-engine.md

File metadata and controls

46 lines (34 loc) · 1.48 KB

Routing Engine

RoutingEngine is part of Environment and it's used to register Route or RouteProvider instances.

Example

void init(Environment environment) {
  environment.routingEngine()
      .registerAutoRoute(Route.sync("GET", "/ping", requestContext -> "pong"))
      .registerAutoRoutes(new MyResource());
}

The implementation of MyResource as a class by itself.

class MyResource implements RouteProvider {

  @Override
  public Stream<? extends Route<? extends AsyncHandler<?>>> routes() {
    return Stream.of(
        Route.sync("GET", "/v1/address/<name>", requestContext -> "!"/* do work */),
        Route.sync("PUT", "/v1/address/<name>", requestContext -> "!"/* do work */)
    );
  }
}

Overlapping route paths

Say you have defined two routes that overlap in a way that makes one of them a specific case of the other more general one. An example of such an overlap is:

  1. /foo/bar
  2. /foo/<arg>

Route 2 can match calls to /foo/bar too, thus making route 1 a special case of route 2. In this case, the RoutingEngine will route to the more specific routes before more general ones.

Path parameters

Use /foo/<arg:path> to match a path parameter, that may include slashes.