Annotation Type Route
-
@Repeatable(Routes.class) @Retention(RUNTIME) @Target(METHOD) public @interface Route
This annotation can be used to configure a reactive route in a declarative way.The target business method must be non-private and non-static. The annotated method can accept arguments of the following types:
io.vertx.ext.web.RoutingContext
io.vertx.mutiny.ext.web.RoutingContext
io.quarkus.vertx.web.RoutingExchange
io.vertx.core.http.HttpServerRequest
io.vertx.core.http.HttpServerResponse
io.vertx.mutiny.core.http.HttpServerRequest
io.vertx.mutiny.core.http.HttpServerResponse
Param
:class Routes { @Route String hello(@Param Optional<String> name) { return "Hello " + name.orElse("world"); } }
Header
:class Routes { @Route String helloFromHeader(@Header("My-Header") String header) { return "Hello " + header; } }
Body
:class Routes { @Route(produces = "application/json") Person updatePerson(@Body Person person) { person.setName("Bob"); return person; } }
void
then it has to accept at least one argument that makes it possible to end the response, for exampleRoutingContext
. If the annotated method does not returnvoid
then the arguments are optional.If both
path()
andregex()
are set the regular expression is used for matching.If neither
path()
norregex()
is specified and the handler type is notRoute.HandlerType.FAILURE
then the route will match a path derived from the name of the method. This is done by de-camel-casing the name and then joining the segments with hyphens.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description String[]
consumes
Used for content-based routing.Route.HttpMethod[]
methods
int
order
If set to a positive number, it indicates the place of the route in the chain.String
path
String[]
produces
Used for content-based routing and stream serialization.String
regex
Route.HandlerType
type
-
-
-
Element Detail
-
path
String path
- Returns:
- the path
- See Also:
Router.route(String)
- Default:
- ""
-
-
-
regex
String regex
- Returns:
- the path regex
- See Also:
Router.routeWithRegex(String)
- Default:
- ""
-
-
-
methods
Route.HttpMethod[] methods
- Returns:
- the HTTP methods
- See Also:
Route.methods()
- Default:
- {}
-
-
-
type
Route.HandlerType type
- Returns:
- the type of the handler
- Default:
- io.quarkus.vertx.web.Route.HandlerType.NORMAL
-
-
-
produces
String[] produces
Used for content-based routing and stream serialization.If no
Content-Type
header is set then try to use the most acceptable content-type. If the request does not contain an 'Accept' header and no content type is explicitly set in the handler then the content type will be set to the first content type in the array. When a route returns aMulti
, this attribute is used to define how that stream is serialized. In this case, accepted values are:ReactiveRoutes.APPLICATION_JSON
- Encode the response into a JSON Array, where each item is sent one by one,ReactiveRoutes.EVENT_STREAM
- Encode the response as a stream of server-sent-events,ReactiveRoutes.ND_JSON
orReactiveRoutes.JSON_STREAM
- Encode the response as JSON stream, when each item is sent one by one with a `\n` as delimiter between them
Multi
, no special serialization is applied. The items are sent one-by-one without delimiters.- Returns:
- the produced content types
- See Also:
Route.produces(String)
,RoutingContext.getAcceptableContentType()
- Default:
- {}
-
-
-
consumes
String[] consumes
Used for content-based routing.- Returns:
- the consumed content types
- See Also:
Route.consumes(String)
- Default:
- {}
-
-