Annotation 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
Furthermore, it is possible to inject the request parameters into a method parameter annotated with 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.

  • 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

      Returns:
      the type of the handler
      Default:
      NORMAL
    • order

      int order
      If set to a positive number, it indicates the place of the route in the chain.
      See Also:
      • Route.order(int)
      Default:
      0
    • 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 a Multi, this attribute is used to define how that stream is serialized. In this case, accepted values are:

      When this attribute is not set, and the route returns a 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:
      {}