示例: 使用平台 REST API 发布包含 SOAP API 的产品
请查看此示例场景,了解如何使用 API Connect 该平台的 REST API 发布包含 SOAP API 的产品。
此示例演示如何格式化发布产品的请求,并包含用于说明产品定义, API 定义和 SOAP API 的 WSDL 描述的样本文件。
使用 Catalogs API
使用该 API Connect 平台的 Catalogs API 发布产品:
- 要将产品发布到目录,请使用以下语法:
POST catalogs/{org}/{catalog}/publish - 要将产品发布到目录中的空间,请另外使用以下语法指定空间:
POST catalogs/{org}/{catalog}/{space}/publish
这两种情况下的有效内容都是包含三个必需部分和一个可选部分的多部分格式编码主体:
- (必需) 名为
product且介质类型为application/yaml或application/json的部件,其中包含要发布的产品的 yaml 或 JSON 源。 - (必需) 出现一个或多个名为
openapi且介质类型为application/yaml或application/json的部件,其中包含产品中每个 API 的 YAML 或 JSON 源。 - (SOAP API 必需) 出现一个或多个名为
wsdl的部件,其介质类型为application/wsdl,application/wsdl+xml,text/xml或application/zip,其中包含与 API 内容相关联的 WSDL 定义 (以及引用的 XSD 文件 (如果适用))。 - (可选) 名为
gateway_service_urls且介质类型为application/yaml或application/json的部件,它是 URL 的 YAML 或 JSON 数组,用于将目录或空间中配置的网关服务的子集指定为发布目标。 可以使用以下调用来获取这些 URL:- 对于目录:
GET /api/catalogs/{org}/{catalog}/configured-gateway-services - 对于空间:
GET /spaces/{org}/{catalog}/{space}/configured-gateway-services
- 对于目录:
在 product 内容中, apis 部分中对 API 的引用的形式非常重要。 每个 API 引用都必须使用 name 属性,而不是可能在其他情况下出现的 $ref 表单。 以下示例显示了以正确格式引用 API globalweather 版本 1.0.0 的产品:
info:
version: 1.0.0
title: GlobalWeatherProduct
name: globalweatherproduct
plans:
...
apis:
globalweather1.0.0:
name: globalweather:1.0.0
...
使用 cURL 的示例发布操作
此示例将包含 SOAP API 的产品发布到 onlineBanking 提供者组织的 沙箱 目录中,使用 curl -F 选项创建一组表单编码的有效内容部件,并使用 @ 前缀从文件中读取每个部件的内容。 记下部件名 (product, openapi, wsdl) 以及 type= 值给出的每个部件的内容类型。
在此示例中,先前已检索到访问令牌,并将其放置在名为 TOKEN的环境变量中。 为了便于阅读,该命令拆分为多行,但必须作为单行输入。
请求:
curl -v -k
-F "product=@globalweatherproduct_1.0.0.yaml;type=application/yaml"
-F "openapi=@globalweather_1.0.0.yaml;type=application/yaml"
-F "wsdl=@globalweather.wsdl;type=application/wsdl"
-H "Authorization: Bearer $TOKEN"
-H 'Content-Type: multipart/form-data'
-H 'Accept: */*' https://dev.apic.example.com/api/catalogs/onlinebanking/sandbox/publish
回复:
201 Created
{
"type": "product",
"api_version": "2.0.0",
"id": "d03129a4-9a99-4c88-85e6-d51bbf312164",
"name": "globalweatherproduct",
"version": "1.0.0",
"title": "GlobalWeatherProduct",
"state": "published",
"scope": "catalog",
"gateway_types": [
"datapower-api-gateway"
],
"billing_urls": [],
"api_urls": [
"https://dev.apic.example.com/api/catalogs/87227774-d297-4064-8908-b8f0b1db71a5/1bc8f4ba-4178-4a4b-93e8-96a8ca9667fd/apis/d5986b78-d556-4457-8c38-951c471f57fc"
],
"gateway_service_urls": [
"https://dev.apic.example.com/api/catalogs/87227774-d297-4064-8908-b8f0b1db71a5/1bc8f4ba-4178-4a4b-93e8-96a8ca9667fd/configured-gateway-services/a416f39d-39e1-484c-9f7e-4a599abefec8"
],
"oauth_provider_urls": [],
"plans": [
{
"title": "Default Plan",
"name": "default-plan",
"apis": [
{
"id": "d5986b78-d556-4457-8c38-951c471f57fc",
"name": "globalweather",
"title": "GlobalWeather",
"version": "1.0.0",
"url": "https://dev.apic.example.com/api/catalogs/87227774-d297-4064-8908-b8f0b1db71a5/1bc8f4ba-4178-4a4b-93e8-96a8ca9667fd/apis/d5986b78-d556-4457-8c38-951c471f57fc"
}
]
}
],
"visibility": {
"view": {
"type": "public",
"enabled": true
},
"subscribe": {
"type": "authenticated",
"enabled": true
}
},
"task_urls": [],
"created_at": "2021-12-15T07:35:40.295Z",
"updated_at": "2021-12-15T07:35:40.295Z",
"org_url": "https://dev.apic.example.com/api/orgs/87227774-d297-4064-8908-b8f0b1db71a5",
"catalog_url": "https://dev.apic.example.com/api/catalogs/87227774-d297-4064-8908-b8f0b1db71a5/1bc8f4ba-4178-4a4b-93e8-96a8ca9667fd",
"url": "https://dev.apic.example.com/api/catalogs/87227774-d297-4064-8908-b8f0b1db71a5/1bc8f4ba-4178-4a4b-93e8-96a8ca9667fd/products/d03129a4-9a99-4c88-85e6-d51bbf312164"
该请求指定了三个文件,这些文件包含在此示例中以供参考: