Skip to main content
Version: 1.1-beta

Routing

Routing refers to the process by which an API gateway forwards a client request to the corresponding backend service based on a specific path or conditions from the request. An API gateway is an intermediary layer situated between the client and server, responsible for managing, monitoring, and routing client API requests. Its routing functionality is one of the core features of an API gateway.

In an API gateway, routing is typically based on various conditions such as URL path, HTTP method (e.g., GET, POST), request headers, and query parameters. When the API gateway receives a client request, it decides which backend service to forward the request to based on pre-configured routing rules.

Routing Matching Rulesโ€‹

APIPark's routing can be configured with multiple criteria, including request protocol, request method, request path, request headers, and query parameters.

The matching priority is: Request Protocol > Request Method > Request Path > Request Header > Query Parameter

Request Protocol, Request Method can be multi-selected during configuration, as shown below:

Request Path Matching Rulesโ€‹

Match TypeRuleDescription
Exact MatchstrThe value exists and is completely equal to str
Prefix Matchstr*The value exists and str is the prefix of the value; in this mode, the gateway appends the path after str to the forwarding path.

Exact Match Exampleโ€‹

  • Request Path: /shop/user/info
  • Forwarding Path: /user/info

In this case, the request path is as follows:

POST /shop/user/info

The gateway will request the upstream service with the following path:

POST /user/info

If the request path is not /shop/user/info, the route cannot be matched.

Prefix Match Exampleโ€‹

  • Request Path: /shop/user/*
  • Forwarding Path: /user/

In this case, the relationship between the requested path and the actual path forwarded to the upstream service is as follows:

POST /shop/user/info    ->   POST /user/info
POST /shop/user/phone -> POST /user/phone
POST /shop/user/order -> POST /user/order

Request Header, Query Parameter Value Matching Rulesโ€‹

Match TypeRuleDescription
Exact MatchstrThe value exists and is completely equal to str
Prefix Matchstr*The value exists and str is the prefix
Suffix Match*strThe value exists and str is the suffix
Substring MatchstrThe value exists and str is a substring
Not Equal Match!=strThe value exists and differs from str
Empty Value Match$The key must exist and the value must be empty, often used for headers or query parameters
Existence Match**The key must exist and not be empty, often used for headers or query parameters
Non-existence Match!The key must not exist, often used for headers or query parameters
Case-sensitive Regex Match~=strThe value matches the regular expression
Case-insensitive Regex Match~*=strThe value matches the regular expression
Any Match*Always matches successfully

Operations Demonstrationโ€‹

Adding a Routeโ€‹

  1. Select the service to configure and enter the service details page.

  1. Click "Route"

  1. Click "Add Route"

  1. Fill in the basic route information

Field Descriptions

Field NameDescription
Intercept RequestWhether to intercept the request for this interface
Request MethodSupports common HTTP request methods like GET, POST, PUT, DELETE, etc., and allows multiple selections
Request PathThe API's URI used for the relative path in the request URL, supports Restful parameters and path prefix matching
Advanced MatchingSupports routing matches via request headers, parameters, and cookies, allowing multiple entries
Forwarding PathThe relative path for forwarding upstream
Request TimeoutDefines the timeout duration for forwarding requests to upstream until response
Retry CountTriggers automatic retry for forwarding requests upon failure, not exceeding the maximum retry count
Upstream HeaderAllows creation, editing, and deletion of request headers for upstream forwarding, mainly for authentication between the gateway and upstream

After filling, click the "Submit" button.

This guide covers all steps in configuring routing in the application, including selecting routing options, adding routes, choosing request methods, configuring API basic information, and ultimately submitting the configuration.

Editing a Routeโ€‹

  1. Click the Edit button next to the route to be edited.

  1. Fill in the route information.

After completion, click submit.

Deleting a Routeโ€‹

  1. Click the Delete button next to the route to be deleted.

  1. Click confirm in the pop-up box.