Skip to main content

Version: 3.11.0

Configure Routes

Apache APISIX provides flexible gateway management capabilities based on routes, in which routing paths and target upstreams are defined.

A route is a routing path to upstream targets. In Apache APISIX, routes are responsible for matching client's requests based on defined rules, loading and executing the corresponding plugins, as well as forwarding requests to the specified upstream services. A simple route can be set up with a path-matching URI and a corresponding upstream address.

An upstream is a set of target nodes with the same work. It defines a virtual host abstraction that performs load balancing on a given set of service nodes according to the configured rules.

This tutorial guides you through how to create a route and verify it. You will:

  1. Create a route with a sample upstream that points to an httpbin service.
  2. Send a request to the route to see how APISIX proxies the request.

Prerequisite(s)

  1. Complete Get APISIX to install APISIX in Docker or on Kubernetes.

Start a Sample Upstream Service

If you are running APISIX in Kubernetes, you will be deploying an httpbin application to your cluster in this section. Otherwise, skip to the next section where you will be using the hosted httpbin application as the upstream.

Start a sample httpbin application:

kubectl run httpbin --image kennethreitz/httpbin --port 80

You should see a pod/httpbin created response.

Expose the application's port 80 through a service:

kubectl expose pod httpbin --port 80

You should see a service/httpbin exposed response.

Create a Route

In this section, you will create a route that forwards client requests to httpbin, an HTTP request and response service.

curl -i "http://127.0.0.1:9180/apisix/admin/routes" -X PUT -d '
{
"id": "getting-started-ip",
"uri": "/ip",
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'

You will receive an HTTP/1.1 201 Created response if the route was created successfully.

Verify

Send a request to the route:

curl "http://127.0.0.1:9080/ip"

You should see a response similar to the following:

{
"origin": "183.94.122.205"
}

What's Next

This tutorial creates a route pointing to one upstream node. In the next tutorial, you will learn how to configure load balancing with multiple upstream nodes.


API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation