Annotation Interface Route
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:
class Routes {
@Route
String hello(@Param Optional<String> name) {
return "Hello " + name.orElse("world");
}
}
The request headers can be injected into a method parameter annotated with Header:
class Routes {
@Route
String helloFromHeader(@Header("My-Header") String header) {
return "Hello " + header;
}
}
The request body can be injected into a method parameter annotated with Body:
class Routes {
@Route(produces = "application/json")
Person updatePerson(@Body Person person) {
person.setName("Bob");
return person;
}
}
If the annotated method returns void then it has to accept at least one argument that makes it possible to end the
response, for example RoutingContext.
If the annotated method does not return void then the arguments are optional.
If both path() and regex() are set the regular expression is used for matching.
If neither path() nor regex() is specified and the handler type is not Route.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumRepresents an HTTP method.static @interface -
Optional Element Summary
Optional Elements
-
Element Details
-
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:
- NORMAL
-
order
int orderIf set to a positive number, it indicates the place of the route in the chain.- See Also:
-
Route.order(int)
- Default:
- 0
-
produces
String[] producesUsed 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[] consumesUsed for content-based routing.- Returns:
- the consumed content types
- See Also:
-
Route.consumes(String)
- Default:
- {}
-