Interface Router

All Known Implementing Classes:
DefaultRouter, FilteredRouter

public interface Router

Core Router interface that allows discovery of a route given an HTTP method and URI.

Since:
1.0
Author:
Graeme Rocher
  • Method Details

    • findAny

      <T, R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull CharSequence uri, @Nullable HttpRequest<?> context)
      Find any RouteMatch regardless of HTTP method.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      context - The optional HttpRequest context information to apply RouteMatchFilter.
      Returns:
      A stream of route matches
    • findAny

      <T, R> @NonNull List<UriRouteMatch<T,R>> findAny(@NonNull HttpRequest<?> request)
      Find any RouteMatch regardless of HTTP method.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      request - The request
      Returns:
      A stream of route matches
      Since:
      4.0.0
    • getExposedPorts

      Set<Integer> getExposedPorts()
      Returns:
      The exposed ports.
    • applyDefaultPorts

      void applyDefaultPorts(List<Integer> ports)
      Sets the ports the application will listen to by default.
      Parameters:
      ports - The default ports
    • find

      <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull HttpMethod httpMethod, @NonNull CharSequence uri, @Nullable HttpRequest<?> context)
      Finds all possible routes for the given HTTP method and URI.
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      httpMethod - The HTTP method
      uri - The URI route match
      context - The optional HttpRequest context information to apply RouteMatchFilter.
      Returns:
      A Stream of possible Route instances.
    • find

      default <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull HttpMethod httpMethod, @NonNull URI uri, @Nullable HttpRequest<?> context)
      Finds all possible routes for the given HTTP method and URI.
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      context - The optional HttpRequest context
      Returns:
      A Stream of possible Route instances.
    • find

      default <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull HttpRequest<?> request)
      Finds all possible routes for the given HTTP request.
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      request - The HTTP request
      Returns:
      A Stream of possible Route instances.
    • find

      default <T, R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull HttpRequest<?> request, @NonNull CharSequence uri)
      Find method, that should be used for non-standard http methods. For standards, it should act the same as find(HttpMethod, CharSequence, HttpRequest)
      Type Parameters:
      T - The target type.
      R - The type of what
      Parameters:
      request - The request, that can have overridden HttpRequest.getMethodName()
      uri - The URI route match.
      Returns:
      A Stream of possible Route instances.
    • findAllClosest

      <T, R> @NonNull List<UriRouteMatch<T,R>> findAllClosest(@NonNull HttpRequest<?> request)
      Finds the closest match for the given request.
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      request - The request
      Returns:
      A List of possible Route instances.
      Since:
      1.2.1
    • findClosest

      default <T, R> @Nullable UriRouteMatch<T,R> findClosest(@NonNull HttpRequest<?> request) throws DuplicateRouteException
      Finds the closest match for the given request or null if none is found.
      Type Parameters:
      T - The target type
      R - The type
      Parameters:
      request - The request
      Returns:
      A match or null, throws DuplicateRouteException on multiple routes.
      Throws:
      DuplicateRouteException
      Since:
      4.0.0
    • uriRoutes

      @NonNull Stream<UriRouteInfo<?,?>> uriRoutes()
      Returns all UriRoutes.
      Returns:
      A Stream of all registered UriRoute instances.
    • route

      <T, R> Optional<UriRouteMatch<T,R>> route(@NonNull HttpMethod httpMethod, @NonNull CharSequence uri)
      Finds the first possible route for the given HTTP method and URI.
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      httpMethod - The HTTP method
      uri - The URI
      Returns:
      The route match
    • route

      <R> Optional<RouteMatch<R>> route(@NonNull HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      Type Parameters:
      R - The matched route
      Parameters:
      status - The HTTP status
      Returns:
      The RouteMatch
    • route

      <R> Optional<RouteMatch<R>> route(@NonNull Class<?> originatingClass, @NonNull HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      status - The HTTP status
      Returns:
      The RouteMatch
    • route

      <R> Optional<RouteMatch<R>> route(@NonNull Throwable error)
      Match a route to an error.
      Type Parameters:
      R - The matched route
      Parameters:
      error - The error
      Returns:
      The RouteMatch
    • route

      <R> Optional<RouteMatch<R>> route(@NonNull Class<?> originatingClass, @NonNull Throwable error)
      Match a route to an error.
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      error - The error
      Returns:
      The RouteMatch
    • findErrorRoute

      <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull Class<?> originatingClass, @NonNull Throwable error, HttpRequest<?> request)
      Match a route to an error.
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      error - The error
      request - The request
      Returns:
      The RouteMatch
    • findErrorRoute

      <R> Optional<RouteMatch<R>> findErrorRoute(@NonNull Throwable error, HttpRequest<?> request)
      Match a route to an error.
      Type Parameters:
      R - The matched route
      Parameters:
      error - The error
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull Class<?> originatingClass, @NonNull HttpStatus status, HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      status - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      default <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request)
      Found a RouteMatch for the given status code.
      Type Parameters:
      R - The matched route
      Parameters:
      originatingClass - The class the error originates from
      statusCode - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull HttpStatus status, HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      Type Parameters:
      R - The matched route
      Parameters:
      status - The HTTP status
      request - The request
      Returns:
      The RouteMatch
    • findStatusRoute

      default <R> Optional<RouteMatch<R>> findStatusRoute(int statusCode, HttpRequest<?> request)
      Found a RouteMatch for the given status code.
      Type Parameters:
      R - The matched route
      Parameters:
      statusCode - The HTTP status code
      request - The request
      Returns:
      The RouteMatch
    • findFilters

      @NonNull List<GenericHttpFilter> findFilters(@NonNull HttpRequest<?> request)
      Find filters for the request.
      Parameters:
      request - The request
      Returns:
      filters
    • findFilters

      default @NonNull List<GenericHttpFilter> findFilters(@NonNull HttpRequest<?> request, @Nullable RouteMatch<?> routeMatch)
      Find filters for the request and a route match.
      Parameters:
      request - The request
      routeMatch - The route match
      Returns:
      filters
      Since:
      4.6
    • findPreMatchingFilters

      default @NonNull List<GenericHttpFilter> findPreMatchingFilters(@NonNull HttpRequest<?> request)
      Find pre-matching filters for the request.
      Parameters:
      request - The request
      Returns:
      filters
      Since:
      4.6
    • GET

      default <T, R> Optional<UriRouteMatch<T,R>> GET(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.GET method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • POST

      default <T, R> Optional<UriRouteMatch<T,R>> POST(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.POST method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • PUT

      default <T, R> Optional<UriRouteMatch<T,R>> PUT(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.PUT method and the given URI.
      Type Parameters:
      T - The target type
      R - The URI route match
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • PATCH

      default <T, R> Optional<UriRouteMatch<T,R>> PATCH(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.PATCH method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • DELETE

      default <T, R> Optional<UriRouteMatch<T,R>> DELETE(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.DELETE method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • OPTIONS

      default <T, R> Optional<UriRouteMatch<T,R>> OPTIONS(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.OPTIONS method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch
    • HEAD

      default <T, R> Optional<UriRouteMatch<T,R>> HEAD(@NonNull CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.HEAD method and the given URI.
      Type Parameters:
      T - The target type
      R - The return type
      Parameters:
      uri - The URI
      Returns:
      An Optional of RouteMatch