Class RouteHandler

java.lang.Object
dev.mccue.microhttp.handler.RouteHandler
All Implemented Interfaces:
Handler

public abstract class RouteHandler extends Object implements Handler
Template for a handler that handles a single route by matching on the request's uri path and filtering on the request's method.
  • Constructor Details

    • RouteHandler

      protected RouteHandler(String method, Pattern pattern)
  • Method Details

    • handleRoute

      protected abstract @Nullable IntoResponse handleRoute(Matcher routeMatch, org.microhttp.Request request) throws Exception
      Throws:
      Exception
    • of

      public static RouteHandler of(String method, Pattern pattern, Handler handler)
    • of

      public static RouteHandler of(String method, Pattern pattern, RouteHandler.MatcherHandler handler)
    • handle

      public final @Nullable IntoResponse handle(org.microhttp.Request request) throws Exception
      Description copied from interface: Handler
      Handles the request.

      If null is returned, that means that the handler is signaling that it does not want to handle the Request. This would signal that another Handler should be consulted or a default response should be used

      Specified by:
      handle in interface Handler
      Parameters:
      request - The request to handle.
      Returns:
      Something which can be converted into a response or null.
      Throws:
      Exception - If something goes wrong.