Class HttpRoute

    • Constructor Detail

      • HttpRoute

        public HttpRoute​(HttpMethod method,
                         HttpPattern pattern,
                         HttpRouteHandler handler)
        Creates new HttpService route.
        Parameters:
        method - HTTP method to require for given requests to match this route. Use null to allow any method.
        pattern - HTTP pattern to require for given request paths to match this route. Use null to allow any path.
        handler - The handler to execute with matching requests.
    • Method Detail

      • method

        public java.util.Optional<HttpMethod> method()
        Specified by:
        method in interface HttpRoutable
        Returns:
        HttpMethod, if any, that routed requests must match for this route to be invoked.
      • pattern

        public java.util.Optional<HttpPattern> pattern()
        Specified by:
        pattern in interface HttpRoutable
        Returns:
        HttpPattern, if any, that the paths of routed requests must match for this route to be invoked.
      • match

        public boolean match​(HttpRouteTask task,
                             java.util.List<java.lang.String> pathParameters)
        Checks whether the request in the given task matches this route, without providing the request to the handler owned by this route.
        Parameters:
        task - Incoming HTTP request route task.
        pathParameters - List to store any matching path parameters to.
        Returns:
        true only if request matches this route.
      • handle

        public Future<?> handle​(HttpServiceRequest request,
                                HttpServiceResponse response)
                         throws java.lang.Exception
        Makes this route handle the given HTTP request.
        Parameters:
        request - Information about the incoming HTTP request, including its header and body.
        response - An object useful for indicating how the request is to be responded to.
        Returns:
        Future completed when handling is complete.
        Throws:
        java.lang.Exception - Whatever exception the handle may want to throw. If the HTTP service owning this handle knows how to translate the exception into a certain kind of HTTP response, it should. Otherwise the requester should receive a 500 Internal Server Error response without any details and the exception be logged (if logging is enabled).