📅  最后修改于: 2023-12-03 15:37:18.135000             🧑  作者: Mango
在编写 API 文档时,需要包含以下内容:
## Endpoints
### Get User
* URL: /users/{id}
* Method: GET
* Description: Retrieves user information by ID.
## Request Parameters
### Query Parameters
| Parameter | Type | Required | Description |
|-----------|---------|----------|---------------------------------|
| name | string | no | Filter by name |
| age | number | no | Filter by age |
### Request Headers
| Header | Type | Required | Description |
|--------|---------|----------|---------------------------------|
| Authorization | string | yes | Access token for authorization |
### Request Body
| Parameter | Type | Required | Description |
|-----------|---------|----------|---------------------------------|
| name | string | yes | User's name |
| age | number | yes | User's age |
## Response Information
### Success Response
* Status Code: 200 OK
* Body:
```json
{
"name": "John",
"age": 18,
"gender": "male"
}
{
"error": "User not found"
}
4. **示例请求和响应**: 包含请求和响应的示例,以便开发人员快速了解如何使用 API,如下所示:
```markdown
## Sample Request
```http
GET /users/123 HTTP/1.1
Host: example.com
Authorization: Bearer <access_token>
{
"name": "John",
"age": 18,
"gender": "male"
}
{
"error": "User not found"
}
在编写 API 文档时,应该尽可能详细地描述每个端点并提供示例请求和响应,以使开发人员轻松使用 API。