Package kos.core
Class SimplifiedRouter
java.lang.Object
kos.core.SimplifiedRouter
- All Implemented Interfaces:
io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
public class SimplifiedRouter
extends Object
implements io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
Small layer that wraps
Router aiming to simplify a few common
aspects regarding route configuration, like intercepting requests
and the reading body requests in a POST, PUT and PATCH requests.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RequestInterceptorHandlerprivate final KosContextprivate final io.vertx.ext.web.Router -
Constructor Summary
ConstructorsModifierConstructorDescriptionSimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod, Boolean> httpMethodsThatMayReadBody) privateSimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, RequestInterceptorHandler interceptor, Map<io.vertx.core.http.HttpMethod, Boolean> httpMethodsThatMayReadBody) -
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(io.vertx.core.http.HttpServerRequest event) voidintercept(io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> interceptor) Registers aHandlerto intercept all received requests.voidintercept(RequestInterceptor interceptor) Registers aRequestInterceptorto intercept all requests.voidintercept(RequestInterceptor interceptor, boolean tryHandleExceptions) Registers aRequestInterceptorto intercept all requests.voidroute(io.vertx.core.http.HttpMethod method, String path, io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> handler) Routes requests made topathto a particular handler.voidroute(io.vertx.core.http.HttpMethod method, String path, RequestHandler handler) Routes requests made topathto a particular handler.io.vertx.ext.web.Routerunwrap()Returns the wrapped Vert.xRouter.static SimplifiedRouterwrapWithAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router) Creates an instance ofSimplifiedRouterthat will automatically read the request body payload for PATCH, POST and PUT.static SimplifiedRouterwrapWithNoAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router) Creates a basic instance ofSimplifiedRouter.
-
Field Details
-
router
private final io.vertx.ext.web.Router router -
interceptorHandler
-
httpMethodsThatMayReadBody
-
kosContext
-
-
Constructor Details
-
SimplifiedRouter
public SimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod, Boolean> httpMethodsThatMayReadBody) -
SimplifiedRouter
private SimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, RequestInterceptorHandler interceptor, Map<io.vertx.core.http.HttpMethod, Boolean> httpMethodsThatMayReadBody)
-
-
Method Details
-
unwrap
public io.vertx.ext.web.Router unwrap()Returns the wrapped Vert.xRouter.- Returns:
- the wrapped Vert.x
Router
-
intercept
Registers aRequestInterceptorto intercept all requests.- Parameters:
interceptor- the interceptor handler.
-
intercept
Registers aRequestInterceptorto intercept all requests.- Parameters:
tryHandleExceptions- if set true, it will wrap the interceptor and try to handle possible exceptions that might be thrown. It won't be capable to handle those that might happen on a different thread though.interceptor- the interceptor handler.
-
intercept
public void intercept(io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> interceptor) Registers aHandlerto intercept all received requests.- Parameters:
interceptor- The interceptor handler
-
route
Routes requests made topathto a particular handler.- Parameters:
method- Http Method used by this endpointpath- relative URI used by this endpointhandler- request handler
-
route
public void route(io.vertx.core.http.HttpMethod method, String path, io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> handler) Routes requests made topathto a particular handler.- Parameters:
method- Http Method used by this endpointpath- relative URI used by this endpointhandler- request handler
-
wrapWithAutoBodyReader
public static SimplifiedRouter wrapWithAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router) Creates an instance ofSimplifiedRouterthat will automatically read the request body payload for PATCH, POST and PUT.- Parameters:
router- the router instance that will be wrapped- Returns:
- An instance of
SimplifiedRouter
-
wrapWithNoAutoBodyReader
public static SimplifiedRouter wrapWithNoAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router) Creates a basic instance ofSimplifiedRouter. Developers that use instances created by this method should configure themselves how to read the request body payload.- Parameters:
router- the router instance that will be wrapped- Returns:
- An instance of
SimplifiedRouter
-
handle
public void handle(io.vertx.core.http.HttpServerRequest event) - Specified by:
handlein interfaceio.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
-