/** * Add a path-prefix to the routes declared in the routeGroup * The path() method adds a path-fragment to a path-stack, adds * routes from the routeGroup, then pops the path-fragment again. * It's used for separating routes into groups, for example: * path("/api/email", () -> { * ....post("/add", EmailApi::addEmail); * ....put("/change", EmailApi::changeEmail); * ....etc * }); * Multiple path() calls can be nested. * * @param path the path to prefix routes with * @param routeGroup group of routes (can also contain path() calls) */ public static void path(String path, RouteGroup routeGroup) { getInstance().path(path, routeGroup); }
/** * Add a path-prefix to the routes declared in the routeGroup * The path() method adds a path-fragment to a path-stack, adds * routes from the routeGroup, then pops the path-fragment again. * It's used for separating routes into groups, for example: * path("/api/email", () -> { * ....post("/add", EmailApi::addEmail); * ....put("/change", EmailApi::changeEmail); * ....etc * }); * Multiple path() calls can be nested. * * @param path the path to prefix routes with * @param routeGroup group of routes (can also contain path() calls) */ public static void path(String path, RouteGroup routeGroup) { getInstance().path(path, routeGroup); }
@Override public void initialize() { if (isInitialized()) { return; } service = Service.ignite() .ipAddress(configuration.bindAddress()) .port(configuration.bindPort()); service.path("/v1", () -> { service.get("/version", v1RequestHandler::handleGetVersion); service.get("/status", v1RequestHandler::handleGetStatus); service.delete("/kernel", v1RequestHandler::handleDeleteKernel); } ); service.exception(IllegalArgumentException.class, (exception, request, response) -> { response.status(400); response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8); response.body(exception.getMessage()); }); service.exception(IllegalStateException.class, (exception, request, response) -> { response.status(500); response.type(HttpConstants.CONTENT_TYPE_TEXT_PLAIN_UTF8); response.body(exception.getMessage()); }); initialized = true; }
service.path("/v1", () -> v1RequestHandler.addRoutes(service));