跳到主要内容

宠物 API 函数

借助这些 API 函数,您可以管理商店数据库中的宠物。

添加新宠物

将新宠物添加到商店数据库中。

接口:https://petstore3.swagger.io/api/v3/pet

操作:POST

示例

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"
}'

响应

代码描述
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"
}

参数

请求正文
名称类型描述
bodyPet 对象(必填) 要添加到存储库的 Pet 对象。

更新现有宠物

根据 ID 更新现有宠物。

接口:https://petstore3.swagger.io/api/v3/pet

操作:PUT

示例

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"
}'

响应

代码描述
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

示例

GET "https://petstore3.swagger.io/api/v3/pet/findByStatus?status=available" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"

响应

代码描述
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
允许的值: availablependingsold

按标签查找宠物

根据标签查找宠物。

接口:https://petstore3.swagger.io/api/v3/pet/findByTags

操作:GET

示例

GET "https://petstore3.swagger.io/api/v3/pet/findByTags?tags=string" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"

响应

代码描述
200操作成功
400输入无效
default意外错误
响应示例

200: Successful operation

[
{
"id": 210,
"name": "Krypto",
"category": {
"id": 1,
"name": "Dogs"
},
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
]

参数

查询参数
名称类型描述
tagsarray用于筛选的标签。
默认值: []
允许的值: 任何有效的标签名称。

按 ID 查找宠物

根据宠物的唯一 ID 查找宠物。

接口:https://petstore3.swagger.io/api/v3/pet/{petId}

操作:GET

示例

GET "https://petstore3.swagger.io/api/v3/pet/210" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"

响应

代码描述
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

示例

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"

响应

代码描述
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

示例

DELETE "https://petstore3.swagger.io/api/v3/pet/210" \
-H "api_key: <YOUR_API_KEY>"

响应

代码说明
200宠物已删除
400提供的 ID 无效
404未找到宠物

(删除成功时返回 200 代码,且无响应正文。)

参数

路径参数
名称类型描述
petId整数待删除宠物的 ID

上传图片

为宠物上传图片。

接口:https://petstore3.swagger.io/api/v3/pet/{petId}/uploadImage

操作:POST

示例

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"

响应

代码描述
200操作成功
default意外错误
响应示例

200: Successful operation

{
"code": 200,
"type": "unknown",
"message": "additional data"
}

参数

路径参数
名称类型描述
petId整数要更新的宠物 ID
表单数据参数
名称类型描述
additionalMetadata字符串要传递给服务器的额外数据。
file文件要上传的文件。