A rule in AI Gateway determines how incoming requests are matched and forwarded to services. Rules act as the traffic routing configuration that maps incoming requests to the appropriate services based on paths, methods, and other conditions.
The path matching system provides multiple strategies for routing requests based on URL patterns. Exact path matching provides the most precise control, ensuring requests match specific URLs exactly as configured. For more flexible routing, the system supports prefix matching with wildcards, allowing a single rule to capture multiple similar paths. More complex routing needs can be addressed using regular expression patterns, enabling sophisticated pattern matching for special use cases. The system employs priority-based selection when multiple patterns match, ensuring the most specific and appropriate rule is selected for each request.
Method matching controls how HTTP methods are handled for each route. Rules can be configured to accept specific HTTP methods, ensuring endpoints only respond to intended operations. The system supports multiple method support, allowing a single rule to handle different types of requests on the same path. Administrators can implement method restrictions to limit which HTTP operations are allowed, providing an additional layer of security and control over API access.
Header matching provides advanced request routing based on HTTP headers. Rules can match based on headers, allowing routing decisions to be made on factors like API versions, client types, or custom metadata. The system includes support for multiple headers, enabling complex routing scenarios based on combinations of header values. Regular expression patterns can be applied to header values, providing flexible matching capabilities for complex header-based routing requirements.
The system prioritizes precision and specificity in path matching to ensure the most appropriate rule is selected. Exact paths take precedence over pattern-based matches, providing the highest level of routing precision. When comparing similar paths, the system follows a length-based hierarchy where longer paths are preferred over shorter ones, as they typically represent more specific endpoints. This approach ensures that more specific matches win in cases where multiple rules could apply, preventing ambiguous routing situations and maintaining precise control over request handling.
HTTP method matching follows a clear hierarchy in determining rule priority. Rules with method-specific rules are given higher priority, as they represent more precisely defined routing intentions. At the lowest priority level are rules with ALL methods, providing a catch-all mechanism for general routing scenarios. The system ensures that explicit methods take precedence over wildcards, allowing for precise method-based routing while maintaining flexibility through wildcard rules when needed. This hierarchical approach to method matching ensures that requests are handled by the most specifically defined rules while still providing fallback options for more general cases.