宠物 API 函数
借助这些 API 函数,您可以管理商店数据库中的宠物。
添加新宠物
将新宠物添加到商店数据库中。
接口:https://petstore3.swagger.io/api/v3/pet
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/pet" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d '{
"id": 0,
"name": "string",
"category": {
"id": 0,
"name": "string"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}'
POST "https://petstore3.swagger.io/api/v3/pet" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-d '{
"id": 0,
"name": "string",
"category": {
"id": 0,
"name": "string"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}'
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 输入无效 |
| 404 | 未找到宠物 |
| 422 | 验证异常 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
参数
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | Pet 对象 | (必填) 要添加到存储库的 Pet 对象。 |
更新现有宠物
根据 ID 更新现有宠物。
接口:https://petstore3.swagger.io/api/v3/pet
操作:PUT
示例
- API 密钥
- OAuth 2.0
PUT "https://petstore3.swagger.io/api/v3/pet" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d '{
"id": 210,
"name": "Krypto",
"status": "available"
}'
PUT "https://petstore3.swagger.io/api/v3/pet" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-d '{
"id": 210,
"name": "Krypto",
"status": "available"
}'
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 输入无效 |
| 404 | 未找到宠物 |
| 422 | 验证异常 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
参数
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | 宠物对象 | (必填) 要更新的宠物对象。 |
按状态查找宠物
根据宠物状态进行查询。
接口:https://petstore3.swagger.io/api/v3/pet/findByStatus
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/pet/findByStatus?status=available" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/pet/findByStatus?status=available" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 输入无效 |
| default | 意外错误 |
响应示例
200: Successful operation
[
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
]
参数
查询参数
| 名称 | 类型 | 描述 |
|---|---|---|
| status | 字符串 | 要查找的宠物的状态。 默认值: available。允许的值: available、pending、sold。 |
按标签查找宠物
根据标签查找宠物。
接口:https://petstore3.swagger.io/api/v3/pet/findByTags
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/pet/findByTags?tags=string" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/pet/findByTags?tags=string" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 输入无效 |
| default | 意外错误 |
响应示例
200: Successful operation
[
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
]
参数
查询参数
| 名称 | 类型 | 描述 |
|---|---|---|
| tags | array | 用于筛选的标签。 默认值: []。允许的值: 任何有效的标签名称。 |
按 ID 查找宠物
根据宠物的唯一 ID 查找宠物。
接口:https://petstore3.swagger.io/api/v3/pet/{petId}
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/pet/210" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/pet/210" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 提供的 ID 无效 |
| 404 | 未找到宠物 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| petId | 整数 | 要返回的宠物 ID |
使用表单数据更新宠物
使用表单数据更新存储中的宠物。
接口:https://petstore3.swagger.io/api/v3/pet/{petId}
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/pet/210" \
-H "api_key: <YOUR_API_KEY>" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "name=Krypto" \
--data-urlencode "status=available"
POST "https://petstore3.swagger.io/api/v3/pet/210" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "name=Krypto" \
--data-urlencode "status=available"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 405 | 输入无效 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| petId | 整数 | 要更新的宠物 ID |
查询参数
| 名称 | 类型 | 描述 |
|---|---|---|
| name | 字符串 | 待更新的宠物名称 |
| status | 字符串 | 待更新的宠物状态 |
删除宠物
从数据库中删除一只宠物。
接口:https://petstore3.swagger.io/api/v3/pet/{petId}
操作:DELETE
示例
- API 密钥
- OAuth 2.0
DELETE "https://petstore3.swagger.io/api/v3/pet/210" \
-H "api_key: <YOUR_API_KEY>"
DELETE "https://petstore3.swagger.io/api/v3/pet/210" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 说明 |
|---|---|
| 200 | 宠物已删除 |
| 400 | 提供的 ID 无效 |
| 404 | 未找到宠物 |
(删除成功时返回 200 代码,且无响应正文。)
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| petId | 整数 | 待删除宠物的 ID |
上传图片
为宠物上传图片。
接口:https://petstore3.swagger.io/api/v3/pet/{petId}/uploadImage
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/pet/210/uploadImage" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-H "api_key: <YOUR_API_KEY>" \
--form "file=@/path/to/your/file"
POST "https://petstore3.swagger.io/api/v3/pet/210/uploadImage" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
--form "file=@/path/to/your/file"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"code": 200,
"type": "unknown",
"message": "additional data"
}
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| petId | 整数 | 要更新的宠物 ID |
表单数据参数
| 名称 | 类型 | 描述 |
|---|---|---|
| additionalMetadata | 字符串 | 要传递给服务器的额外数据。 |
| file | 文件 | 要上传的文件。 |