Annotation Interface WebRoute
Specifies a web route in a web controller.
A web route is an annotated method in a web controller which basically implements the exchange handler logic. The method parameters can be bound to the request parameters or the request body using
annotations like @CookieParam
, @FormParam
,
@HeaderParam
, @PathParam
,
@QueryParam
and @Body
.
Some specific method parameter can also be specified when needed like the exchange being processed declared as Exchange
or WebExchange
and a server-sent event factory as described
by SseEventFactory
.
The method's return type describes the payload of the response, it can either be:
void
to produce an empty responseByteBuf
,Mono<ByteBuf>
,Flux<ByteBuf>
orPublisher<ByteBuf>
to produce raw dataMono<T>
,Flux<T>
orPublisher<T>
where typeT
is a super type ofWebResponseBody.SseEncoder.Event<ByteBuf>
to produce server-sent events with raw dataMono<T>
,Flux<T>
orPublisher<T>
where typeT
is a super type ofWebResponseBody.SseEncoder.Event<U>
and U not aByteBuf
to produce server-sent events with encoded data based on the media type specified by the@SseEventFactory
annotated method parameterResource
to produce a static resourceT
,Mono<T>
,Flux<T>
orPublisher<T>
whereT
is none of the above to produce encoded data based on the content type of the response
A response payload is encoded using one of the MediaTypeConverter
injected in the web server module and corresponding to the content type of the response which is automatically set in case of
successful content negotiation, basically when there's a match between the media type produced by the route and what the client accepts, otherwise the response content type must be set explicitly
or an InternalServerErrorException
stating that no media was specified will be thrown.
A simple web route can be defined as follows in a web controller bean:
@WebController( path = "/book" )
@Bean
public class BookController {
@WebRoute( path = "{id}", method = Method.PUT, consumes = "application/json", produces = "application/json" )
public Book update(@Body Book book) {
...
}
}
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionString[]
The list of media ranges that the content type of a request must match to be served by the route as defined by RFC 7231 Section 5.3.2.String[]
The list of languages that a request must match (i.e. accept at least one of them) to be served by the route.boolean
Indicates whether trailing slash in the request path should be matched by the route.Method[]
The list of HTTP methods to which the method of a request must belong to be served by the route.String[]
The path that the absolute path of a request must match to be served by the route.String[]
The list of media types that the request must match (i.e. accept at least one of them) to be served by the route.
-
Element Details
-
method
Method[] methodThe list of HTTP methods to which the method of a request must belong to be served by the route.
- Returns:
- an array of HTTP methods
- Default:
{}
-
path
String[] pathThe path that the absolute path of a request must match to be served by the route.
A path can be a parameterized path parameters as defined by
URIBuilder
.Note that this path will be normalized in the resulting route.
- Returns:
- an array of path
- Default:
{}
-
matchTrailingSlash
boolean matchTrailingSlashIndicates whether trailing slash in the request path should be matched by the route.
When activated, the route matches a path regardless of whether it ends with a slash as long as the path matches one of the paths specified in the route with or without trailing slash.
- Returns:
- true to match path with or without trailing slash, false otherwise
- Default:
false
-
consumes
String[] consumesThe list of media ranges that the content type of a request must match to be served by the route as defined by RFC 7231 Section 5.3.2.
- Returns:
- an array of media ranges
- Default:
{}
-
produces
String[] producesThe list of media types that the request must match (i.e. accept at least one of them) to be served by the route.
- Returns:
- an array of media types
- Default:
{}
-
language
String[] languageThe list of languages that a request must match (i.e. accept at least one of them) to be served by the route.
- Returns:
- an array of language tags
- Default:
{}
-