@Repeatable(value=Route.Routes.class) @Retention(value=RUNTIME) @Target(value=METHOD) public @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.reactivex.ext.web.RoutingContextio.quarkus.vertx.web.RoutingExchangeio.vertx.core.http.HttpServerRequestio.vertx.core.http.HttpServerResponseio.vertx.reactivex.core.http.HttpServerRequestio.vertx.reactivex.core.http.HttpServerResponseParam:
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.
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 set 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.
| Modifier and Type | Optional Element and Description |
|---|---|
String[] |
consumes
Used for content-based routing.
|
io.vertx.core.http.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.
|
String |
regex |
Route.HandlerType |
type |
public abstract String path
Router.route(String)public abstract String regex
Router.routeWithRegex(String)public abstract io.vertx.core.http.HttpMethod[] methods
Route.methods()public abstract Route.HandlerType type
public abstract int order
Route.order(int)public abstract String[] produces
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.
Route.produces(String),
RoutingContext.getAcceptableContentType()public abstract String[] consumes
Route.consumes(String)Copyright © 2020 JBoss by Red Hat. All rights reserved.