Create a route

更新时间:
复制 MD 格式

When Cloud-native API Gateway processes an incoming request, it evaluates the configured route rules in descending order of priority. If a request matches a rule, the gateway forwards it to the backend service defined in that rule. If no rule matches, the gateway returns a 404 error.

Route matching priority

The prioritization rules are as follows: Associated Domain Name > Path > Header > Query Parameters > Created At.

  1. Based on the Associated Domain Name: The longer the domain string, the higher the priority.

  2. Based on the Path:

    • For different Match Rule types, the priority is: Equals To > Prefix > Regular Expression Match.

    • For the same Match Rule type, a longer Path string has higher priority.

  3. Based on the total number of key-value pairs in the Header: The more pairs, the higher the priority.

  4. Based on the total number of key-value pairs in the Query Parameters: The more pairs, the higher the priority.

  5. Based on the Created At: The earlier the creation time, the higher the priority.

Procedure

Note
  • Route configuration supports the HTTP protocol suite, including HTTP/1.0, HTTP/1.1, HTTP/2.0, gRPC, and WebSocket.

  • Routes created within an instance are visible and manageable only in that specific instance.

  1. Cloud-native API Gateway provides two ways to create routes: from outside an instance or from within an instance.

    Outside instance

    1. Log on to the Cloud-native API Gateway console. In the navigation pane on the left, choose API. In the top menu bar, select a region.

    2. Click the target API. In the drop-down list that appears, select the instance where the route will be configured, or select All Instances. From the All Instances drop-down menu at the top, select the target instance.

    3. Click Create Route.

    Inside instance

    1. Log on to the Cloud-native API Gateway console. In the navigation pane on the left, choose Instance. In the top menu bar, select a region.

    2. On the Instance page, click the ID of the target gateway instance. In the navigation pane on the left, choose API, and then click the target API.

    3. Click Create Route.

  2. On the Create Route page, configure the parameters, and then click Save or Save and Publish.

    Note
    • Match rules are combined using a logical AND. The more rules you specify, the narrower the matching scope.

    • The matching priority of routes corresponds to their display order on the route configuration page.

    Parameter

    Description

    Route Name

    Enter a custom name for the route.

    Route Description

    Click Add Route Description to enter a description for the route.

    Domain Name

    • Select one or more domains for the route to match.

    • To create a new domain, click Add Domain and create it in the panel that appears.

    Path

    Specifies the path parameter in the HTTP request to match.

    • For the same match rule type, a longer path string has higher priority.

    • For different match rule types, the priority is: Equals To > Prefix > Regular Expression Match.

      • Equals To: The request path must be an exact match. For example, it must be exactly /user.

      • Prefix: The request path must start with the specified prefix, for example, /user.

      • Regular Expression Match: The request path must match the specified regular expression.

    Method

    Specifies the method parameter in the HTTP request to match. You can select multiple HTTP methods. The default is ANY.

    Header

    Specifies the header parameters in the HTTP request to match. For the same match rule type, a rule with more parameters has higher priority.

    Query Parameters

    Specifies the query parameters in the HTTP request to match. For the same match rule type, a rule with more parameters has higher priority.

    Instance

    Select the Cloud-native API Gateway instance where the route will take effect.

    Scenario

    Select the target service type for the current route.

    • Basic: Single Service

    • Grayscale release: By Percentage (Multi-service), Tag (Tag-based Routing)

    • Other: Mock, Redirect

    For more information about different types of target services, see Routes.

    Note

    The sum of traffic weights for all weighted target services must be 100%.

    Backend Services

    Select an associated backend service and port.

    Note
    • You can click Associated Service to select a source and service in the panel.

    • Different source types have different limits on the number of sources you can add.

      • You can add a maximum of five sources for Container Service.

      • You can add only one Nacos or Zookeeper source.

    Timeout Period (seconds)

    Enter the timeout duration. The default is 60 seconds. A value of 0 indicates no timeout.

    Fallback

    Specify a fallback service. If the backend service for a route has no available nodes, the gateway routes the original request to the specified fallback service.

    Note

    Currently, the fallback feature is supported only between HTTP services.

    Retry Times

    Enter the number of retries. The default is 2. A value of 0 disables retries.

    Retry Condition

    Select the conditions that trigger a retry.

    Retry Status Code

    Add one or more status codes that trigger a retry.