本页面适用于 Apigee 和 Apigee Hybrid。
本文档介绍如何在已注册的 API 之间创建和管理依赖项。依赖项可帮助您了解 API 之间的关系。请参阅依赖项简介。
创建依赖项
您可以使用 REST API 创建依赖项实体。
REST
如需使用创建依赖项 API 创建新的依赖项,请执行以下操作:
curl -X POST 'https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies?dependency_id=DEPENDENCY_ID' \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H 'Content-Type: application/json' \ --d '{ "description": "DESCRIPTION", "supplier": { "operation_resource_name": SUPPLIER_OPERATION }, "consumer": { "operation_resource_name": CONSUMER_OPERATION } }'
请替换以下内容:
- HUB_PROJECT:API Hub 宿主项目的名称。预配 API Hub 时选择了宿主项目。
- HUB_LOCATION:宿主项目的位置。该位置是在预配 API Hub 时选择的。
- DEPENDENCY_ID:(可选)依赖项的标识符。如果未提供,将使用系统生成的 ID。名称必须是 4-500 个字符的字符串,其中有效字符为
/[a-z][A-Z][0-9]-_.
- DESCRIPTION:(可选)依赖项的简要说明。
- SUPPLIER_OPERATION:(必需)提供方操作的完全限定名称。例如:
"projects/myproject/locations/us-central1/apis/payments-api/versions/locationv1/operations/getlocation"
。 - CONSUMER_OPERATION:(必需)使用方操作的完全限定名称。此操作依赖于(调用)提供方操作。例如:
"projects/myproject/locations/us-central1/apis/payments-api/versions/locationv1/operations/createuser"
。
示例响应:
{ "name": "projects/myproject/locations/us-central1/dependencies/user-to-pet", "consumer": { "displayName": "POST - /v2/user", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/createuser" }, "supplier": { "displayName": "POST - /v2/pet", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/addpet" }, "state": "VALIDATED", "description": "Dependency from user to pet API", "discoveryMode": "MANUAL", "createTime": "2024-04-17T19:33:31.664226Z", "updateTime": "2024-04-17T19:33:31.664226Z" }
示例 REST
curl -X POST 'https://apihub.googleapis.com/v1/projects/myproject/locations/us-central1/dependencies?dependency_id=user-to-pet' \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H 'Content-Type: application/json' \ --d '{ "description": "Dependency from user to pet API", "consumer": { "operation_resource_name": "projects/myproject/locations/us-central1/apis/payments-api/versions/paymentv1/operations/createuser" }, "supplier": { "operation_resource_name": "projects/myproject/locations/us-central1/apis/pet-api/versions/petstorev1/operations/addpet" } }'
列出依赖项
本部分介绍如何列出依赖项。您可以列出与 API 的所有版本关联的所有依赖项,或列出与特定版本关联的所有依赖项。
REST
如需列出所有依赖项,请使用列出依赖项 API:
curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies" -H "Authorization: Bearer: $(gcloud auth print-access-token)" -X GET -H "Content-Type: application/json"
请替换以下内容:
- HUB_PROJECT:API Hub 宿主项目的名称。预配 API Hub 时选择了宿主项目。
- HUB_LOCATION:宿主项目的位置。该位置是在预配 API Hub 时选择的。
示例输出:
{ "dependencies": [ { "name": "projects/myproject/locations/us-central1/dependencies/user-to-pet", "consumer": { "displayName": "POST - /v2/user", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/createuser" }, "supplier": { "displayName": "POST - /v2/pet", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/addpet" } } ] }
获取依赖项详细信息
本部分介绍如何通过 REST API 获取有关 API 依赖项的详细信息。
REST
如需查看依赖项的详细信息,请使用获取依赖项详细信息 API:
curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies/DEPENDENCY_ID" -H "Authorization: Bearer: $(gcloud auth print-access-token)" -X GET -H "Content-Type: application/json"
请替换以下内容:
- HUB_PROJECT:API Hub 宿主项目的名称。预配 API Hub 时选择了宿主项目。
- HUB_LOCATION:宿主项目的位置。该位置是在预配 API Hub 时选择的。
- DEPENDENCY_ID:依赖项的唯一 ID。
示例响应:
{ "name": "projects/myproject/locations/us-central1/dependencies/user-to-pet", "consumer": { "displayName": "POST - /v2/user", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/createuser" }, "supplier": { "displayName": "POST - /v2/pet", "operationResourceName": "projects/myproject/locations/us-central1/apis/payments-api/versions/version1/operations/addpet" }, "state": "VALIDATED", "description": "Dependency from user to pet API", "discoveryMode": "MANUAL", "createTime": "2024-04-17T19:33:31.215978712Z", "updateTime": "2024-04-17T19:33:31.737505297Z" }
删除 API 依赖项
本部分介绍如何删除 API 依赖项。
REST
如需从 API Hub 中删除依赖项,请使用删除依赖项 API:
curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies/DEPENDENCY_ID" -H "Authorization: Bearer: $(gcloud auth print-access-token)" -X DELETE -H "Content-Type: application/json"
请替换以下内容:
- HUB_PROJECT:API Hub 宿主项目的名称。预配 API Hub 时选择了宿主项目。
- HUB_LOCATION:宿主项目的位置。该位置是在预配 API Hub 时选择的。
- DEPENDENCY_ID:要删除的依赖项的 ID。
修改依赖项
本部分介绍如何修改依赖项。唯一可修改的属性是说明。
REST
如需修改部署,请使用修补依赖项 API:
curl "https://apihub.googleapis.com/v1/projects/HUB_PROJECT/locations/HUB_LOCATION/dependencies/DEPENDENCY_ID" -H "Authorization: Bearer: $(gcloud auth print-access-token)" -X PATCH -H "Content-Type: application/json" '{ 'description': DESCRIPTION {'
请替换以下内容:
- HUB_PROJECT:API Hub 宿主项目的名称。预配 API Hub 时选择了宿主项目。
- HUB_LOCATION:宿主项目的位置。该位置是在预配 API Hub 时选择的。
- DEPLOYMENT_ID:要修改的部署的 ID。
- DESCRIPTION:唯一可修改的属性是说明。