Routes
Understand the concept of routes in Apache APISIX, which define paths to upstream services and facilitate effective traffic management.
Overview
Routes define paths to upstream services. In APISIX, a route object is used to create a route when APISIX operates on the application layer, as opposed to a stream route object, which is used to create a route when APISIX functions as a stream proxy operating on the transport layer. Routes are responsible for matching client requests based on configured rules, loading and executing the corresponding plugins, and forwarding requests to the specified upstream endpoints.
A route can be set up with a path-matching URI and a corresponding upstream address. The diagram below shows two HTTP requests sent to the APISIX API gateway and forwarded according to the rules configured in routes:
Routes are often configured with plugins as well. For example, configuring the rate-limit plugin in a route will enable rate-limiting effects.
Router options
APISIX offers three HTTP routing options:
-
radixtree_host_uriroutes requests by hosts and URI paths, prioritizing hostnames over URI paths during matching. This is the default setting. It can be used to route north-south traffic between clients and servers. -
radixtree_uriroutes requests by hosts and URI paths, prioritizing URI paths over hostnames during matching. It can be used to route east-west traffic, such as between microservices. -
radixtree_uri_with_parameterenhancesradixtree_urito support the use of parameter in path matching.
These routing options can be configured in conf/config.yaml under apisix.router.http. APISIX routing is backed by the luaradixtree library. For more information, see Router Options.
Routes, upstreams, and services
Routes define the paths of traffic flows, but repetitive route configuration has drawbacks — hard coding the same upstream addresses or plugin names for a group of routes. On every update, you have to find the repeated fields on each of those routes and change them one by one, which raises the maintenance cost in large-scale systems with many routes.
To address this issue, Upstreams and Services were designed to abstract away repetitive information and reduce redundancies, following the DRY principle.
Related
Tasks that use this concept
Related concepts
- Key Concepts - Stream Routes
- Admin API - Routes