4.2. OpenAPI 文档示例:Petstore API
要从原始源读取规格,请参阅 OpenAPI 规范。
在 OAS 站点上,有多个定义 API 的 OpenAPI 文档示例。如果您希望按照示例学习,您可以按照 OAS API 团队的 Petstore API 示例进行操作。
Petstore API 是一个极其简单的 API。它是一种学习工具,而不是用于生产的工具。
Petstore API 方法
Petstore API 由 4 个方法组成:
-
GET /api/pets
- 返回系统中的所有 pets -
POST /api/pets
- 在存储中创建新宠物 -
GET /api/pets/{id}
- 根据单个 ID 返回 pet -
DELETE /api/pets/{id}
- 根据 ID 删除一个 pet
Petstore API 与 3scale 集成,因此您必须添加额外的参数来进行身份验证。例如,对于用户密钥身份验证方法,API 使用者必须将 user key 参数放在每个请求的标头中。有关其它验证方法的详情,请参考 身份验证模式。
用户密钥参数
user_key: {user_key}
user_key 将由 API 用户在其请求中发送到您的 API。API 用户将使用 3scale 管理员的开发人员门户获取这些密钥。在收到密钥时,3scale 管理员必须使用 Service Management API 对 3scale 执行授权检查。
更多关于 OpenAPI 规范的信息
对于您的 API 用户,在 cURL 调用中表示的 API 文档应如下所示:
curl -X GET "http://example.com/api/pets?tags=TAGS&limit=LIMIT" -H "user_key: {user_key}" curl -X POST "http://example.com/api/pets" -H "user_key: {user_key}" -d "{ "name": "NAME", "tag": "TAG", "id": ID }" curl -X GET "http://example.com/api/pets/{id}" -H "user_key: {user_key}" curl -X DELETE "http://example.com/api/pets/{id}" -H "user_key: {user_key}"
curl -X GET "http://example.com/api/pets?tags=TAGS&limit=LIMIT" -H "user_key: {user_key}"
curl -X POST "http://example.com/api/pets" -H "user_key: {user_key}" -d "{ "name": "NAME", "tag": "TAG", "id": ID }"
curl -X GET "http://example.com/api/pets/{id}" -H "user_key: {user_key}"
curl -X DELETE "http://example.com/api/pets/{id}" -H "user_key: {user_key}"