@azbake/ingredient-apim-api

中文文档
0.2.48发布于 2026/07/23MITTypeScriptCommonJS近 30 天下载 3776

Ingredient for deploying an Azure API Management Instance.

原始使用文档
文档目录10 节
  1. Changelogs
  2. Overview
  3. Ingredient Name
  4. How to include in a recipe
  5. How to use as an ingredient instance
  6. Parameters
  7. Utility Functions
  8. apimapi class
  9. Utility function examples
  10. Sample

Changelogs

Overview

The APIM API ingredient allows for easy registration & modification of APIs within an Azure APIM resource.

Ingredient Name

@azbake/ingredient-apim-api

How to include in a recipe

name: My package
shortName: mypkg
version: 0.0.1
ingredients:
  - "@azbake/ingredient-apim-api@~0" #include the latest version of the ingredient at build time
parallelRegions: false #typically we only want to deploy to the primary region, so can turn off parallel deploy
resourceGroup: false #If the recipe only contains an apim api deployment, you don't need to create resource groups

How to use as an ingredient instance

recipe:
  apim-api-deploy:
    properties:
      type: "@azbake/ingredient-apim-api" #ingredient type
      source: "<azure_resource_group_name>/<azure_apim_resource_name>" #identity the azure apim resource to register an API against
      condition: "[coreutils.primary_region()]" #make sure we only execute this against the primary region for multi-region configs
      parameters:
        ... #see documentation below on parameter documentation for how to use.

Parameters

Here is the documentation for all the supported paremeters for this ingredient.

options

options:
  apiWaitSeconds: <number>   # Supply a number of seconds to wait for any xml-link/swagger-link urls to become availabile 
                             # before creating the APIM api/policy/etc.
                             # You might be deploying a new API in this recipe, which could take 30-120s to become online.
                             # This setting lets us wait for new APIs to be online
  forceWait: <boolean>       # forces bake to wait the `apiWaitSeconds` value even if the API exists. Useful for allowing a
                             # k8s service deployment to update when using the same version.
  apiRetries: <number>       # number of times the ingredient will retry to add the API
  apiRetryWaitTime: <number> # seconds between retries      

apis

apis: #follows this azure spec for *ApiVersionSetContract* : https://github.com/Azure/azure-sdk-for-js/blob/01898c51c663be4c53e02034a0468cf550ce5279/sdk/apimanagement/arm-apimanagement/src/models/index.ts#L3215
  - name: <api-version-name> #unique id for the API (version set) - required
    versions:
      - versionSchema #See next section for version schema

api[n].versions

versions: #follows this azure spec for *ApiCreateOrUpdateParameter* : https://github.com/Azure/azure-sdk-for-js/blob/01898c51c663be4c53e02034a0468cf550ce5279/sdk/apimanagement/arm-apimanagement/src/models/index.ts#L180
  - name: <api-name> #typically you want set the id to <api-version-id>-<version> to keep the id consistant for the version set it belongs to - required
    version: <string> #version string that will be used as part of the above ApiVersionSetContract.versioningSchema
    products: #optional list of product names to assign API to
    policies: #see next section for policy schema
    diagnostics: #see next section for diagnostic schema

Note: ApiCreateOrUpdateParameter.serviceUrl and ApiCreateOrUpdateParameter.value support being defined as BakeVariables. This allows you to set these two values as an expression to resolve endpoint/data dynamically during deployment

api.versions[n].policies

policies: #scheme follows this azure spec for *PolicyContract* : https://github.com/Azure/azure-sdk-for-js/blob/01898c51c663be4c53e02034a0468cf550ce5279/sdk/apimanagement/arm-apimanagement/src/models/index.ts#L3097
  - operation: <string> #optional, and if not set this will be the default policy set for the entire api. Otherwise, name of an operation within this api to apply the policy to.

api.versions[n].diagnostics

diagnostics: #follows this azure spec for *DiagnosticSettingsResource* : https://github.com/Azure/azure-sdk-for-js/blob/20fe312b1122b21811f9364e3d95fe77202e6466/sdk/monitor/arm-monitor/src/models/index.ts#L991
  - name: <diagnostics name> #required name of diagnostics settings

Utility Functions

Utility classes can be used inside of the bake.yaml file for parameter and source values.

apimapi class

FunctionReturnsDescription
get_api(resourceGroup: string, apimName: string, apiId: string)Promise<ApiGetResponse>Returns the API for a given set of parameters.
get_backend(resourceGroup: string, apimName: string, backendId: string)Promise<BackendGetResponse>Returns the back end for a given set of parameters.
get_hostheader(namespace: string, k8sHostname: string, serviceName: string)stringReturns host header for API
get_swaggerUrl(namespace: string, k8sHostname: string, version: string, serviceName: string, protocol: string)stringReturns swagger url page for the API

Utility function examples

variables:
  api: "[await apimapi.get_api(<apim resource group>, <apim name>, <api id>)]"
  backend: "[await apimapi.get_backend(<apim resource group>, <apim name>, <backend id>)]"
  hostHeader: "[await apimapi.get_hostheader(<api namespace>, <k8sHostName>)]"
  swaggerUrl: "[await apimapi.get_swaggerUrl(<api namespace>, <k8sHostName>), <api version>]"

Sample

name: my-api
shortName: myApi
owner: owner
version: 1.0.0
ingredients:
  - "@azbake/ingredient-apim-api@~0"
  - "@azbake/ingredient-app-insights@~0"
resourceGroup: false #no need to create a resource group, just assigning to existing APIM instance
parallelRegions: false
variables:  
  url: http://petstore.swagger.io/v2/swagger.json
  aiName: "[appinsights.get_resource_name('apim-api')]"
  apimName: "[apim.get_resource_name('api')]"
  apimResourceGroup: "[apim.get_resource_group()]"
  # build the source from helper functions
  apimSource: "[apim.get_resource_group() + '/' + apim.get_resource_name('api')]"
recipe:
  my-api-deploy:
    properties:
      type: "@azbake/ingredient-apim-api"
      source: "[coreutils.variable('apimSource')]" #point to existing APIM resource to add API
      condition: "[coreutils.primary_region()]"
      parameters:
        options:
          apiWaitTime: 60 # override to waiting up to 60s for the API to be ready
          forceWait: true # force wait 60s before updating the API in APIM
          apiRetries: 2 # retry adding the API this number of times
          apiRetryWaitTime: 5 # number of seconds between retries
        apis:
          - name: petstore #unique API version identifier across APIM
            displayName: Pet Store API
            description: Pet Store API description
            versioningScheme: Segment
            versions:
              - name: petstore-v1 # unique API identifer across APIM
                version: v1
                apiType: http
                path: pets #base apim url for this api
                protocols: #array of http and/or https
                  - https
                format: swagger-link-json #using a swagger link the value needs to be a http based json document to download
                value: "[coreutils.variable('url')]" #value supports bake variables.
                products:
                  - petstore-product #product should already be created.  if needed you can import APIM ingredient and deploy in the same recipe
                  - starter
                policies: 
                  - format: xml #we use a non-link format here to embed the policy, but this could have been xml-link and a http address
                    value: <policies>
                              <inbound /> 
                              <backend>    
                                <forward-request /> 
                              </backend>  
                              <outbound>
                                <set-header name="X-Powered-By" exists-action="delete" />
                                <set-header name="X-AspNet-Version" exists-action="delete" />
                                <set-header name="CustomHeader" exists-action="override">
                                  <value>{{expressionApiDisplay}}</value>
                                </set-header>
                              </outbound>
                            </policies>
                  - operation: addPet #override the addPet operation policy
                    format: xml
                    value: "<policies> <inbound /> <backend>    </backend>  <outbound /></policies>"
                diagnostics:
                  - name: applicationinsights
                    loggerId: "[(await apim.get_logger(await coreutils.variable('apimResourceGroup'), await coreutils.variable('apimName'), 'aiapim-api')).id]"
                    sampling:
                      samplingType: fixed
                      percentage: 50
              - name: petstore-v2 # unique API identifer across APIM
                version: v2
                apiType: http #unless you're using soap
                path: pets #base apim url for this api
                protocols: #array of http and/or https
                  - https
                format: swagger-link-json #using a swagger link the value needs to be a http based json document to download
                value: "[coreutils.variable('url')]" #value supports bake variables.
                products:
                  - petstore-product
                policies:
                  - format: xml #we use a non-link format here to embed the policy, but this could have been xml-link and a http address
                    value: <policies>
                              <inbound /> 
                              <backend>    
                                <forward-request /> 
                              </backend>  
                              <outbound>
                                <set-header name="X-Powered-By" exists-action="delete" />
                                <set-header name="X-AspNet-Version" exists-action="delete" />
                              </outbound>
                            </policies>
                  - operation: addPet #override the addPet operation policy
                    format: xml
                    value: "<policies> <inbound /> <backend>    </backend>  <outbound /></policies>"

版本与发布记录

@azbake/ingredient-apim-api 共发布 48 个版本,首次发布于 2020/06/19;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.48latest2026/07/233 个月前
0.2.472026/07/213 个月前
0.2.462025/11/071 年前
0.2.452025/11/071 年前
0.2.442024/07/252 年前
0.2.432023/05/253 年前

关于 @azbake/ingredient-apim-api 的常见问题

@azbake/ingredient-apim-api 是什么?

Ingredient for deploying an Azure API Management Instance.

如何安装 @azbake/ingredient-apim-api?

在项目目录运行 npm install @azbake/ingredient-apim-api,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@azbake/core(*)、@azbake/ingredient-utils(*)、@azure/ms-rest-nodeauth(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@azbake/ingredient-apim-api 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azbake/ingredient-apim-api 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@azbake/ingredient-apim-api 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.4.2 <17。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azbake/ingredient-apim-api 可以商用吗?

@azbake/ingredient-apim-api 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azbake/ingredient-apim-api 的下载量有多少?

根据 npm 官方下载统计,@azbake/ingredient-apim-api 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,776 次,日均约 126 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azbake/ingredient-apim-api 还在维护吗?

最新版本 0.2.48 发布于 2026/07/23(3 个月前);至今共发布 48 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/06/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。