Package io.micronaut.web.router
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 Summary
Modifier and TypeMethodDescriptionvoid
applyDefaultPorts
(List<Integer> ports) Sets the ports the application will listen to by default.default <T,
R> Optional<UriRouteMatch<T, R>> DELETE
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.DELETE
method and the given URI.<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.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.default <T,
R> @NonNull Stream<UriRouteMatch<T, R>> find
(@NonNull HttpRequest<?> request) Finds all possible routes for the given HTTP request.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.<T,
R> @NonNull List<UriRouteMatch<T, R>> findAllClosest
(@NonNull HttpRequest<?> request) Finds the closest match for the given request.<T,
R> @NonNull List<UriRouteMatch<T, R>> findAny
(@NonNull HttpRequest<?> request) Find anyRouteMatch
regardless of HTTP method.<T,
R> @NonNull Stream<UriRouteMatch<T, R>> findAny
(@NonNull CharSequence uri, @Nullable HttpRequest<?> context) Find anyRouteMatch
regardless of HTTP method.default <T,
R> @Nullable UriRouteMatch<T, R> findClosest
(@NonNull HttpRequest<?> request) Finds the closest match for the given request or null if none is found.<R> Optional<RouteMatch<R>>
findErrorRoute
(@NonNull Class<?> originatingClass, @NonNull Throwable error, HttpRequest<?> request) Match a route to an error.<R> Optional<RouteMatch<R>>
findErrorRoute
(@NonNull Throwable error, HttpRequest<?> request) Match a route to an error.findFilters
(@NonNull HttpRequest<?> request) Build a filteredPublisher
for an action.default <R> Optional<RouteMatch<R>>
findStatusRoute
(int statusCode, HttpRequest<?> request) Found aRouteMatch
for the given status code.<R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.default <R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request) Found aRouteMatch
for the given status code.<R> Optional<RouteMatch<R>>
findStatusRoute
(@NonNull Class<?> originatingClass, @NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.default <T,
R> Optional<UriRouteMatch<T, R>> GET
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.GET
method and the given URI.default <T,
R> Optional<UriRouteMatch<T, R>> HEAD
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.HEAD
method and the given URI.default <T,
R> Optional<UriRouteMatch<T, R>> OPTIONS
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.OPTIONS
method and the given URI.default <T,
R> Optional<UriRouteMatch<T, R>> PATCH
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.PATCH
method and the given URI.default <T,
R> Optional<UriRouteMatch<T, R>> POST
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.POST
method and the given URI.default <T,
R> Optional<UriRouteMatch<T, R>> PUT
(@NonNull CharSequence uri) Find the firstRouteMatch
route for anHttpMethod.PUT
method and the given URI.<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.<R> Optional<RouteMatch<R>>
route
(@NonNull HttpStatus status) Found aRouteMatch
for the givenHttpStatus
code.<R> Optional<RouteMatch<R>>
route
(@NonNull Class<?> originatingClass, @NonNull HttpStatus status) Found aRouteMatch
for the givenHttpStatus
code.<R> Optional<RouteMatch<R>>
Match a route to an error.<R> Optional<RouteMatch<R>>
Match a route to an error.@NonNull Stream<UriRouteInfo<?,
?>> Returns all UriRoutes.
-
Method Details
-
findAny
@NonNull <T,R> @NonNull Stream<UriRouteMatch<T,R>> findAny(@NonNull @NonNull CharSequence uri, @Nullable @Nullable HttpRequest<?> context) Find anyRouteMatch
regardless of HTTP method.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URIcontext
- The optionalHttpRequest
context information to applyRouteMatchFilter
.- Returns:
- A stream of route matches
-
findAny
Find anyRouteMatch
regardless of HTTP method.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
request
- The request- Returns:
- A stream of route matches
- Since:
- 4.0.0
-
getExposedPorts
- Returns:
- The exposed ports.
-
applyDefaultPorts
Sets the ports the application will listen to by default.- Parameters:
ports
- The default ports
-
find
@NonNull <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull CharSequence uri, @Nullable @Nullable HttpRequest<?> context) Finds all possible routes for the given HTTP method and URI.- Type Parameters:
T
- The target typeR
- The type- Parameters:
httpMethod
- The HTTP methoduri
- The URI route matchcontext
- The optionalHttpRequest
context information to applyRouteMatchFilter
.- Returns:
- A
Stream
of possibleRoute
instances.
-
find
@NonNull default <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull URI uri, @Nullable @Nullable HttpRequest<?> context) Finds all possible routes for the given HTTP method and URI.- Type Parameters:
T
- The target typeR
- The URI route match- Parameters:
httpMethod
- The HTTP methoduri
- The URIcontext
- The optionalHttpRequest
context- Returns:
- A
Stream
of possibleRoute
instances.
-
find
@NonNull default <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpRequest<?> request) Finds all possible routes for the given HTTP request. -
find
@NonNull default <T,R> @NonNull Stream<UriRouteMatch<T,R>> find(@NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull CharSequence uri) Find method, that should be used for non-standard http methods. For standards, it should act the same asfind(HttpMethod, CharSequence, HttpRequest)
- Type Parameters:
T
- The target type.R
- The type of what- Parameters:
request
- The request, that can have overriddenHttpRequest.getMethodName()
uri
- The URI route match.- Returns:
- A
Stream
of possibleRoute
instances.
-
findAllClosest
@NonNull <T,R> @NonNull List<UriRouteMatch<T,R>> findAllClosest(@NonNull @NonNull HttpRequest<?> request) Finds the closest match for the given request. -
findClosest
@Nullable default <T,R> @Nullable UriRouteMatch<T,R> findClosest(@NonNull @NonNull HttpRequest<?> request) throws DuplicateRouteException Finds the closest match for the given request or null if none is found.- Type Parameters:
T
- The target typeR
- The type- Parameters:
request
- The request- Returns:
- A match or null, throws
DuplicateRouteException
on multiple routes. - Throws:
DuplicateRouteException
- Since:
- 4.0.0
-
uriRoutes
Returns all UriRoutes. -
route
<T,R> Optional<UriRouteMatch<T,R>> route(@NonNull @NonNull HttpMethod httpMethod, @NonNull @NonNull CharSequence uri) Finds the first possible route for the given HTTP method and URI.- Type Parameters:
T
- The target typeR
- The URI route match- Parameters:
httpMethod
- The HTTP methoduri
- The URI- Returns:
- The route match
-
route
Found aRouteMatch
for the givenHttpStatus
code.- Type Parameters:
R
- The matched route- Parameters:
status
- The HTTP status- Returns:
- The
RouteMatch
-
route
<R> Optional<RouteMatch<R>> route(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull HttpStatus status) Found aRouteMatch
for the givenHttpStatus
code.- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromstatus
- The HTTP status- Returns:
- The
RouteMatch
-
route
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 @NonNull Class<?> originatingClass, @NonNull @NonNull Throwable error) Match a route to an error.- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromerror
- The error- Returns:
- The
RouteMatch
-
findErrorRoute
<R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull Throwable error, HttpRequest<?> request) Match a route to an error.- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromerror
- The errorrequest
- The request- Returns:
- The
RouteMatch
-
findErrorRoute
<R> Optional<RouteMatch<R>> findErrorRoute(@NonNull @NonNull Throwable error, HttpRequest<?> request) Match a route to an error.- Type Parameters:
R
- The matched route- Parameters:
error
- The errorrequest
- The request- Returns:
- The
RouteMatch
-
findStatusRoute
<R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull Class<?> originatingClass, @NonNull @NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromstatus
- The HTTP statusrequest
- The request- Returns:
- The
RouteMatch
-
findStatusRoute
default <R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull Class<?> originatingClass, int statusCode, HttpRequest<?> request) Found aRouteMatch
for the given status code.- Type Parameters:
R
- The matched route- Parameters:
originatingClass
- The class the error originates fromstatusCode
- The HTTP statusrequest
- The request- Returns:
- The
RouteMatch
-
findStatusRoute
<R> Optional<RouteMatch<R>> findStatusRoute(@NonNull @NonNull HttpStatus status, HttpRequest<?> request) Found aRouteMatch
for the givenHttpStatus
code.- Type Parameters:
R
- The matched route- Parameters:
status
- The HTTP statusrequest
- The request- Returns:
- The
RouteMatch
-
findStatusRoute
Found aRouteMatch
for the given status code.- Type Parameters:
R
- The matched route- Parameters:
statusCode
- The HTTP status coderequest
- The request- Returns:
- The
RouteMatch
-
findFilters
Build a filteredPublisher
for an action.- Parameters:
request
- The request- Returns:
- A new filtered publisher
-
GET
Find the firstRouteMatch
route for anHttpMethod.GET
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
POST
Find the firstRouteMatch
route for anHttpMethod.POST
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
PUT
Find the firstRouteMatch
route for anHttpMethod.PUT
method and the given URI.- Type Parameters:
T
- The target typeR
- The URI route match- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
PATCH
Find the firstRouteMatch
route for anHttpMethod.PATCH
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
DELETE
Find the firstRouteMatch
route for anHttpMethod.DELETE
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
OPTIONS
Find the firstRouteMatch
route for anHttpMethod.OPTIONS
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-
HEAD
Find the firstRouteMatch
route for anHttpMethod.HEAD
method and the given URI.- Type Parameters:
T
- The target typeR
- The return type- Parameters:
uri
- The URI- Returns:
- An
Optional
ofRouteMatch
-