管理 API 产品

使用 apic productsapic apis 命令管理已经发布到 API Connect 目录的产品和 API。[V5.0.5 或更高版本]使用 --scope space 选项来管理发布到目录中空间的产品和 API。

这是在整个生命周期中使用 productsapis 命令的示例:

示例命令 描述
apic config:set catalog=apic-catalog://mgmnthost.com/orgs/climbon/catalogs/sb 设置缺省目录。
apic login --username some-user --password some-password --server mgmnthost.com 登录 mgmnthost.com 云。
apic create --type api --title Routes --product "ClimbOn" 创建产品和 API。
apic publish --stage climbon.yaml 将产品发布到已登台状态。
apic products 列出目录中的产品。
apic products:get climbon 显示产品的属性。
apic apis 列出目录中的 API。
apic apis:get routes 获取 API 的属性。
apic products:set climbon --status published 发布产品,使 API 联机。
apic apis:set routes --status offline 使 API 脱机。
apic apis:set routes --status online 使 API 联机。
apic products:set climbon --status deprecated 废弃产品。
apic products:set climbon --status retired 引退产品。
apic products:set climbon --status archived 归档产品。
apic products:delete climbon 从目录中删除产品。
[V5.0.5 或更高版本]注: 如果定义 API 的 OpenAPI (Swagger 2.0) 文件使用 $ref 字段来引用在单独文件中定义的 OpenAPI (Swagger 2.0) 代码片段,那么在使用 apic publish 命令使包含 API 的产品登台或发布该产品前,将 $ref 字段替换为目标文件的内容。有关更多信息,请参阅[V5.0.5 或更高版本]使用 $ref 以在 OpenAPI (Swagger 2.0) 文件中复用代码片段

以下是更加复杂的生命周期示例,其中新版本产品和 API 会在运行时替换原始版本。

设置缺省目录并登录 mgmnthost.com API Connect 云:

apic config:set catalog=apic-catalog://mgmnthost.com/orgs/climbon/catalogs/sb
apic login --username some-user --password some-password --server mgmnthost.com

创建并发布初始版本:

apic create --type api --title Routes --version 1.0.0 --filename routes100.yaml
apic create --type product --title "Climb On" --version 1.0.0 --apis routes100.yaml --filename climbon100.yaml
apic publish climbon100.yaml

创建新版本以修复 API 中的错误,将其登台至目录:

apic create --type api --title Routes --version 1.0.1 --filename routes101.yaml
apic create --type product --title "Climb On" --version 1.0.1 --apis routes101.yaml --filename climbon101.yaml
apic publish --stage climbon101.yaml

检查目录:

apic products
apic products:get climbon:1.0.0
apic products:get climbon:1.0.1

将 V1.0.0“热替换”为 V1.0.1:

apic products:replace climbon:1.0.0 climbon:1.0.1 --plans default:default

除了生命周期管理功能,您还可以使用 pullclone 子命令在目录中下载产品和 API:

命令 描述
apic products:clone 从目录下载所有产品及其 API。
apic products:pull climbon:1.0.0 从目录下载 climbon:1.0.0 产品及其 API。
apic apis:clone 从目录下载所有 API。
apic apis:pull routes:1.0.0 从目录下载 routes:1.0.0 API。

这也有助于从目录中清除所有产品及其 API,尤其是针对开发目录(您必须提供目录名称作为 --confirm 参数的值):

apic products:clear --confirm catalog_name
其中 catalog_name 是目录名称。

[V5.0.5 或更高版本]您可以使用空间来对目录进行分区,以便多个团队可以在单个目录中独立管理各种产品和 API。每个空间概念上类似于一个子目录,但给定目录中的所有空间内的产品和 API 都会发布到同一个 Developer Portal。有关空间的更多信息,请参阅使用 IBM API Connect 中的联合

要为目录启用空间,请使用以下命令:
apic catalogs:set catalog_name --spaces enabled
[V5.0.5 或更高版本]如果为目录启用空间,那么仅可将产品登台并发布到此目录中的空间。要发布到空间,必须在 publish 命令中包含 --scope space 选项,例如:
apic publish --scope space product.yaml --space space --catalog catalog --organization organization --server server
其中:
  • product 是想要发布的产品的名称。
  • space 是要发布到的空间的名称。
  • catalog 是包含空间的目录的名称。
  • organization 是组织的名称。
  • server 是管理服务器;port number 是可选的(缺省值为 443)。
要管理已发布到空间的产品和 API,请在 apic productsapic apis 命令中包含 --scope space 选项。例如,要列出名为 flights空间中包含的产品,请使用以下命令:
apic products --scope space --space flights --catalog production --organization climbonorg --server mgmnthost.com
时间戳记图标 上次更新时间:2017-10-24