Package kos.core

Class 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.
    • Field Detail

      • router

        private final io.vertx.ext.web.Router router
      • httpMethodsThatMayReadBody

        private final Map<io.vertx.core.http.HttpMethod,​Boolean> httpMethodsThatMayReadBody
    • Constructor Detail

      • SimplifiedRouter

        public SimplifiedRouter​(KosContext kosContext,
                                io.vertx.ext.web.Router router,
                                Map<io.vertx.core.http.HttpMethod,​Boolean> httpMethodsThatMayReadBody)
    • Method Detail

      • unwrap

        public io.vertx.ext.web.Router unwrap()
        Returns the wrapped Vert.x Router.
        Returns:
        the wrapped Vert.x Router
      • intercept

        public void intercept​(RequestInterceptor interceptor)
        Registers a RequestInterceptor to intercept all requests.
        Parameters:
        interceptor - the interceptor handler.
      • intercept

        public void intercept​(RequestInterceptor interceptor,
                              boolean tryHandleExceptions)
        Registers a RequestInterceptor to 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 a Handler to intercept all received requests.
        Parameters:
        interceptor - The interceptor handler
      • route

        public void route​(io.vertx.core.http.HttpMethod method,
                          String path,
                          RequestHandler handler)
        Routes requests made to path to a particular handler.
        Parameters:
        method - Http Method used by this endpoint
        path - relative URI used by this endpoint
        handler - 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 to path to a particular handler.
        Parameters:
        method - Http Method used by this endpoint
        path - relative URI used by this endpoint
        handler - request handler
      • wrapWithAutoBodyReader

        public static SimplifiedRouter wrapWithAutoBodyReader​(KosContext kosContext,
                                                              io.vertx.ext.web.Router router)
        Creates an instance of SimplifiedRouter that 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 of SimplifiedRouter. 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:
        handle in interface io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>