HttpTrigger.route Method

Definition

Defines the route template, controlling which request URLs your function will respond to. The default value if no route is provided is the function name specified in the FunctionName annotation, applied to each Azure Function.

By default when you create a function for an HTTP trigger, or WebHook, the function is addressable with a route of the form http://<yourapp>.azurewebsites.net/api/<funcname>. You can customize this route using this route property. For example, a route of "products/{category:alpha}/{id:int}" would mean that the function is now addressable with the following route instead of the original route: http://<yourapp>.azurewebsites.net/api/products/electronics/357, which allows the function code to support two parameters in the address: category and id. By specifying the route in this way, developers can then add the additional route arguments as arguments into the function by using the BindingName annotation. For example:

@FunctionName("routeTest")
  public HttpResponseMessage<String> routeTest(
      @HttpTrigger(name = "req",
                    methods = {HttpMethod.GET},
                    authLevel = AuthorizationLevel.ANONYMOUS,
                    route = "products/{category:alpha}/{id:int}") 
                    HttpRequestMessage<Optional<String>> request,
      @BindingName("category") String category,
      @BindingName("id") int id,
       final ExecutionContext context
  ) {
           ....
           context.getLogger().info("We have " + category + " with id " + id);
           ....
  }

For more details on the route syntax, refer to the online documentation.

public abstract String route()

Returns

java.lang.String

The route template to use for the annotated function.

Applies to