2021-03-08 14:28:05 +08:00
---
title: Route
---
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
2022-03-17 19:24:06 +08:00
## Description
Routes match the client's request based on defined rules, load and execute the corresponding [plugins ](./plugin.md ), and forwards the request to the specified [Upstream ](./upstream.md ).
2021-03-08 14:28:05 +08:00
2022-03-03 06:19:09 +08:00
A Route mainly consists of three parts:
2021-03-08 14:28:05 +08:00
2022-03-17 19:24:06 +08:00
1. Matching rules (`uri`, `host` , `remote address` )
2022-03-03 06:19:09 +08:00
2. Plugin configuration (current-limit, rate-limit)
3. Upstream information
The image below shows some example Route rules. Note that the values are of the same color if they are identical.
2021-03-08 14:28:05 +08:00
![routes-example ](../../../assets/images/routes-example.png )
2022-03-03 06:19:09 +08:00
All the parameters are configured directly in the Route. It is easy to set up, and each Route has a high degree of freedom.
When Routes have repetitive configurations (say, enabling the same plugin configuration or Upstream information), to update it, we need to traverse all the Routes and modify them. This adds a lot of complexity, making it difficult to maintain.
2021-03-08 14:28:05 +08:00
2022-03-03 06:19:09 +08:00
These shortcomings are independently abstracted in APISIX by two concepts: [Service ](service.md ) and [Upstream ](upstream.md ).
2021-03-08 14:28:05 +08:00
2022-03-17 19:24:06 +08:00
## Example
2022-03-03 06:19:09 +08:00
The Route example shown below proxies the request with the URL `/index.html` to the Upstream service with the address `127.0.0.1:1980` .
2021-03-08 14:28:05 +08:00
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"uri": "/index.html",
"upstream": {
"type": "roundrobin",
"nodes": {
2021-11-26 11:09:39 +08:00
"127.0.0.1:1980": 1
2021-03-08 14:28:05 +08:00
}
}
}'
2022-03-03 06:19:09 +08:00
```
2021-03-08 14:28:05 +08:00
2022-03-03 06:19:09 +08:00
```shell
2021-03-08 14:28:05 +08:00
HTTP/1.1 201 Created
Date: Sat, 31 Aug 2019 01:17:15 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
2021-11-26 11:09:39 +08:00
{"node":{"value":{"uri":"\/index.html","upstream":{"nodes":{"127.0.0.1:1980":1},"type":"roundrobin"}},"createdIndex":61925,"key":"\/apisix\/routes\/1","modifiedIndex":61925},"action":"create"}
2021-03-08 14:28:05 +08:00
```
2022-03-03 06:19:09 +08:00
A successful response indicates that the route was created.
2021-03-08 14:28:05 +08:00
2022-03-17 19:24:06 +08:00
## Configuration
2022-03-03 06:19:09 +08:00
For specific options of Route, please refer to the [Admin API ](../admin-api.md#route ).