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.RoutingContextio.vertx.mutiny.ext.web.RoutingContextio.quarkus.vertx.web.RoutingExchangeio.vertx.core.http.HttpServerRequestio.vertx.core.http.HttpServerResponseio.vertx.mutiny.core.http.HttpServerRequestio.vertx.mutiny.core.http.HttpServerResponse
Param:
The request headers can be injected into a method parameter annotated withclass Routes { @Route String hello(@Param Optional<String> name) { return "Hello " + name.orElse("world"); } }Header:
The request body can be injected into a method parameter annotated withclass Routes { @Route String helloFromHeader(@Header("My-Header") String header) { return "Hello " + header; } }Body:
If the annotated method returnsclass Routes { @Route(produces = "application/json") Person updatePerson(@Body Person person) { person.setName("Bob"); return person; } }voidthen it has to accept at least one argument that makes it possible to end the response, for exampleRoutingContext. If the annotated method does not returnvoidthen 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.FAILUREthen 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[]consumesUsed for content-based routing.Route.HttpMethod[]methodsintorderIf set to a positive number, it indicates the place of the route in the chain.StringpathString[]producesUsed for content-based routing and stream serialization.StringregexRoute.HandlerTypetype
-
-
-
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-Typeheader 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_JSONorReactiveRoutes.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:
- {}
-
-