Path matching rules
API Gateway supports three types of path matching rules: Exact match, Parameter match, and Prefix match.
Exact match
An exact match means that a match is successful only if the request path is identical to the configured path.
Example
For example, assume the matching rule for the current API is GET /path.
Sample requests:
Request 1:
curl http://127.0.0.1/pathRequest 2:
curl http://127.0.0.1/other
Based on the GET /path matching rule, only Request 1 matches the current API.
Parameter match
If you cannot determine the specific request path but know that a value must exist, you can configure a parameter in the path.
Example
For example, assume the matching rule for the current API is GET /path/{id}.
Sample requests:
Request 1:
curl http://127.0.0.1/pathRequest 2:
curl http://127.0.0.1/path/1Request 3:
curl http://127.0.0.1/path/2Request 4:
curl http://127.0.0.1/path/1/2
Based on the GET /path/{id} matching rule, only Request 2 and Request 3 match the current API.
To pass parameters to the backend service, leave the backend service request path empty when you configure the API in the API Gateway console. If you specify a backend service request path, the gateway uses an exact match to request that path.
For example, if you set the backend request path to /user/{name}, the {name} placeholder is not resolved. The gateway sends a request to the backend service using the literal path /user/{name}.
Prefix match
Use a prefix match if you want all requests with a specific prefix to match a single API.
Example
For example, assume the matching rule for the current API is GET /path/*.
Sample requests:
Request 1:
curl http://127.0.0.1/path/1Request 2:
curl http://127.0.0.1/path/2Request 3:
curl http://127.0.0.1/path/1/2
Based on the GET /path/* matching rule, all of these requests match the API.
If you set the prefix match path to /path, only requests for paths such as /path/xxx are matched. Requests for the path /path are not matched.
Conflict resolution
Because API Gateway supports three matching methods, conflicts between APIs can occur. For example, if you define one API with the path /hello and another with the path /{id}, a request to /hello creates a conflict because it matches both definitions.
To resolve these conflicts, API Gateway uses the longest path first rule. If paths have the same length, the following order of precedence applies: Exact match > Parameter match > Prefix match.
Example
This topic describes the following APIs.
The following configurations are listed in ascending order of priority, where * indicates a prefix match.
GET /*
GET /{id}
GET /path
GET /{id}/*
GET /{id}/{name}
GET /{id}/temp
GET /path/*
GET /path/{id}
GET /path/temp
GET /{id}/{name}/{path}Configure path matching rules
When you create an API in the API Gateway console, you can configure the Path Matching Rule. You can select either Exact match or Prefix match. For both matching methods, you can add parameters to the path.