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
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void applyDefaultPorts​(java.util.List<java.lang.Integer> ports)
      Sets the ports the application will listen to by default.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      DELETE​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.DELETE method and the given URI.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpMethod httpMethod, java.lang.CharSequence uri, io.micronaut.http.HttpRequest<?> context)
      Finds all of the possible routes for the given HTTP method and URI.
      default <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpMethod httpMethod, java.net.URI uri, io.micronaut.http.HttpRequest<?> context)
      Finds all of the possible routes for the given HTTP method and URI.
      default <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpRequest<?> request)
      Finds all of the possible routes for the given HTTP request.
      default <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      find​(io.micronaut.http.HttpRequest<?> request, java.lang.CharSequence uri)
      Find method, that should be used for non-standard http methods.
      <T,​R>
      java.util.List<UriRouteMatch<T,​R>>
      findAllClosest​(io.micronaut.http.HttpRequest<?> request)
      Finds the closest match for the given request.
      <T,​R>
      java.util.stream.Stream<UriRouteMatch<T,​R>>
      findAny​(java.lang.CharSequence uri, io.micronaut.http.HttpRequest<?> context)
      Find any RouteMatch regardless of HTTP method.
      <R> java.util.Optional<RouteMatch<R>> findErrorRoute​(java.lang.Class<?> originatingClass, java.lang.Throwable error, io.micronaut.http.HttpRequest<?> request)
      Match a route to an error.
      <R> java.util.Optional<RouteMatch<R>> findErrorRoute​(java.lang.Throwable error, io.micronaut.http.HttpRequest<?> request)
      Match a route to an error.
      java.util.List<io.micronaut.http.filter.HttpFilter> findFilters​(io.micronaut.http.HttpRequest<?> request)
      Build a filtered Publisher for an action.
      <R> java.util.Optional<RouteMatch<R>> findStatusRoute​(io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> findStatusRoute​(java.lang.Class<?> originatingClass, io.micronaut.http.HttpStatus status, io.micronaut.http.HttpRequest<?> request)
      Found a RouteMatch for the given HttpStatus code.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      GET​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.GET method and the given URI.
      java.util.Set<java.lang.Integer> getExposedPorts()  
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      HEAD​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.HEAD method and the given URI.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      OPTIONS​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.OPTIONS method and the given URI.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      PATCH​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.PATCH method and the given URI.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      POST​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.POST method and the given URI.
      default <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      PUT​(java.lang.CharSequence uri)
      Find the first RouteMatch route for an HttpMethod.PUT method and the given URI.
      <T,​R>
      java.util.Optional<UriRouteMatch<T,​R>>
      route​(io.micronaut.http.HttpMethod httpMethod, java.lang.CharSequence uri)
      Finds the first possible route for the given HTTP method and URI.
      <R> java.util.Optional<RouteMatch<R>> route​(io.micronaut.http.HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Class originatingClass, io.micronaut.http.HttpStatus status)
      Found a RouteMatch for the given HttpStatus code.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Class originatingClass, java.lang.Throwable error)
      Match a route to an error.
      <R> java.util.Optional<RouteMatch<R>> route​(java.lang.Throwable error)
      Match a route to an error.
      java.util.stream.Stream<UriRoute> uriRoutes()
      Returns all UriRoutes.
    • Method Detail

      • findAny

        @NonNull
        <T,​R> java.util.stream.Stream<UriRouteMatch<T,​R>> findAny​(@NonNull
                                                                              java.lang.CharSequence uri,
                                                                              @Nullable
                                                                              io.micronaut.http.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
      • getExposedPorts

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

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

        @NonNull
        <T,​R> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                           io.micronaut.http.HttpMethod httpMethod,
                                                                           @NonNull
                                                                           java.lang.CharSequence uri,
                                                                           @Nullable
                                                                           io.micronaut.http.HttpRequest<?> context)
        Finds all of the 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

        @NonNull
        default <T,​R> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                   io.micronaut.http.HttpMethod httpMethod,
                                                                                   @NonNull
                                                                                   java.net.URI uri,
                                                                                   @Nullable
                                                                                   io.micronaut.http.HttpRequest<?> context)
        Finds all of the 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

        @NonNull
        default <T,​R> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                   io.micronaut.http.HttpRequest<?> request)
        Finds all of the 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

        @NonNull
        default <T,​R> java.util.stream.Stream<UriRouteMatch<T,​R>> find​(@NonNull
                                                                                   io.micronaut.http.HttpRequest<?> request,
                                                                                   @NonNull
                                                                                   java.lang.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

        @NonNull
        <T,​R> java.util.List<UriRouteMatch<T,​R>> findAllClosest​(@NonNull
                                                                            io.micronaut.http.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
      • uriRoutes

        @NonNull
        java.util.stream.Stream<UriRoute> uriRoutes()
        Returns all UriRoutes.
        Returns:
        A Stream of all registered UriRoute instances.
      • route

        <T,​R> java.util.Optional<UriRouteMatch<T,​R>> route​(@NonNull
                                                                       io.micronaut.http.HttpMethod httpMethod,
                                                                       @NonNull
                                                                       java.lang.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> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                    io.micronaut.http.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> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                    java.lang.Class originatingClass,
                                                    @NonNull
                                                    io.micronaut.http.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> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                    java.lang.Throwable error)
        Match a route to an error.
        Type Parameters:
        R - The matched route
        Parameters:
        error - The error
        Returns:
        The RouteMatch
      • route

        <R> java.util.Optional<RouteMatch<R>> route​(@NonNull
                                                    java.lang.Class originatingClass,
                                                    @NonNull
                                                    java.lang.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> java.util.Optional<RouteMatch<R>> findErrorRoute​(@NonNull
                                                             java.lang.Class<?> originatingClass,
                                                             @NonNull
                                                             java.lang.Throwable error,
                                                             io.micronaut.http.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> java.util.Optional<RouteMatch<R>> findErrorRoute​(@NonNull
                                                             java.lang.Throwable error,
                                                             io.micronaut.http.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> java.util.Optional<RouteMatch<R>> findStatusRoute​(@NonNull
                                                              java.lang.Class<?> originatingClass,
                                                              @NonNull
                                                              io.micronaut.http.HttpStatus status,
                                                              io.micronaut.http.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

        <R> java.util.Optional<RouteMatch<R>> findStatusRoute​(@NonNull
                                                              io.micronaut.http.HttpStatus status,
                                                              io.micronaut.http.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
      • findFilters

        @NonNull
        java.util.List<io.micronaut.http.filter.HttpFilter> findFilters​(@NonNull
                                                                        io.micronaut.http.HttpRequest<?> request)
        Build a filtered Publisher for an action.
        Parameters:
        request - The request
        Returns:
        A new filtered publisher
      • GET

        default <T,​R> java.util.Optional<UriRouteMatch<T,​R>> GET​(@NonNull
                                                                             java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> POST​(@NonNull
                                                                              java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> PUT​(@NonNull
                                                                             java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> PATCH​(@NonNull
                                                                               java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> DELETE​(@NonNull
                                                                                java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> OPTIONS​(@NonNull
                                                                                 java.lang.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> java.util.Optional<UriRouteMatch<T,​R>> HEAD​(@NonNull
                                                                              java.lang.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