Interface Router

All Known Implementing Classes:
AbstractRouter, SpringWebRouter

public interface Router
A Router is a S3RequestHandler container. The route path must starts with a '/'. "/", "//", "" matches route("/") "/a" matches route("/a") firstly, then match "/{param}" and pass 'a' as value of `param`.
  • Field Details

  • Method Details

    • router

      static Router router()
      Create a default Router instance.
    • route

      Router route(Route rule)
      Register a handler for the request that matched rule.
      Parameters:
      rule - match conditions
      Returns:
      this
    • route

      default Router route(io.netty.handler.codec.http.HttpMethod method, String path, HttpRequestHandler handler)
    • notFound

      Router notFound(HttpRequestHandler handler)
      Set resource not found handler.
      Returns:
      this
    • staticResource

      Router staticResource(String rootPath)
      The router will map the request uri to the relative path of files under the rootPath directory. By default, the router loads static resources from `classpath:static`.
      • The rootPath must be a valid directory, the router will map the request uri to relative path of files under the rootPath directory.
      • If static resource paths conflict with routes registered via route(), the router will ignore static resources.
      Parameters:
      rootPath - static resources root directory or resource path.
      Returns:
      this.
    • exceptionHandler

      <T extends Throwable> Router exceptionHandler(Class<T> exceptionType, ExceptionHandler<T> handler)
      Set a handler for exceptions with exceptionType.
      Type Parameters:
      T - type of the exception to handle..
      Parameters:
      exceptionType - subtype of Throwable.
      handler - handle specific exception.
      Returns:
      this.
    • findExceptionHandler

      ExceptionHandler<Throwable> findExceptionHandler(Class<? extends Throwable> exceptionType)
      Find the best match exception handler for the given exceptionType.
    • match

      Find a handler for the given request according to registered routes. And set the extracted path parameters to HttpRequest.parameters(String).
      Parameters:
      request - HTTP request.
      Returns:
      a matched handler; or null if no matched handlers.