# 使用方法

## 概述

此 API 提供指定城市的限行号信息。用户可以通过 API 查询特定日期的限行规则。

### 基本信息

* **API 基础 URL**: <https://api.8i5.net/traffic/>

### 请求方式

* **HTTP 方法**: `GET`

### 请求参数

| 参数名  | 类型     | 必填 | 描述                          |
| ---- | ------ | -- | --------------------------- |
| city | string | 是  | 城市名称（例如：`xian`、`beijing`）   |
| date | string | 否  | 日期（格式：`YYYY-MM-DD`，默认为当前日期） |

#### 示例请求

```http
GET https://api.8i5.net/traffic?city=xian&date=2024-12-09
```

### 响应格式

#### 成功响应

* **状态码**: `200 OK`
* **内容类型**: `application/json`

**示例响应**

```json
{
    "city": "Xian",
    "date": "2024-12-09",
    "weekday": "周一",
    "limit": "1,6"
}
```

#### 错误响应

1. **城市未找到**

   * **状态码**: `404 Not Found`
   * **响应示例**:

   ```json
   {
       "error": "城市未找到"
   }
   ```
2. **无效的日期格式**

   * **状态码**: `400 Bad Request`
   * **响应示例**:

   ```json
   {
       "error": "无效的日期格式"
   }
   ```
3. **缺少城市参数**

   * **状态码**: `200 OK`
   * **响应示例**:

   ```json
   {
       "city": null,
       "date": null,
       "weekday": "",
       "limit": ""
   }
   ```

### CORS 支持

此 API 允许所有域名进行访问。响应中包含以下头信息：

* `Access-Control-Allow-Origin: *`
* `Access-Control-Allow-Methods: GET`
* `Access-Control-Allow-Headers: Content-Type`

### 常见问题

#### 1. 如何获取今天的限行号？

只需将 `date` 参数留空，API 会返回当前日期的限行号。

#### 2. 如果提供了无效的城市名，会发生什么？

API 会返回 `404 Not Found` 状态和相应的错误信息。

#### 3. 如何处理 CORS 问题？

此 API 允许所有域名访问，无需特别处理 CORS 问题。

***

请根据实际需求调整 API 的基本 URL 和其他内容。这个文档应该能帮助开发者理解如何使用你的 API。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-doc.8i5.net/qi-che-xian-xing/shi-yong-fang-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
