Class HttpRouter

java.lang.Object
io.github.jirkasa.servletrouter.Router<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
io.github.jirkasa.servletrouter.HttpRouter
All Implemented Interfaces:
Handler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>

public class HttpRouter extends Router<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
Implementation of Router that uses HttpServletRequest and HttpServletResponse.

It can be created directly like this:

 HttpRouter router = new HttpRouter();
 router.register("/", HomeController.class);
 router.register("/info", infoRouter);
 
or a subclass can be created (which is recommended) and register methods can be called from the constructor:
 public class AppRouter extends HttpRouter {
     public AppRouter() {
         register("/", HomeController.class);
         register("/info", infoRouter);
     }
 }
 
  • Constructor Details

    • HttpRouter

      public HttpRouter()
  • Method Details

    • getRequestPath

      protected String getRequestPath(javax.servlet.http.HttpServletRequest request)
      Description copied from class: Router
      This method is called by implementation of handle method to get request path.
      Specified by:
      getRequestPath in class Router<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
      Parameters:
      request - Request based on which should be determined request path.
      Returns:
      Request path without leading and trailing slashes. For example "info/about" (not "/info/about/").