Build and register APIs with the Azure API Center extension for Visual Studio Code
API developers in your organization can build and register APIs in your API center inventory by using the Azure API Center extension for Visual Studio Code. API developers can:
- Add an existing API to an API center as a one-time operation, or integrate a development pipeline to register APIs as part of a CI/CD workflow.
- Generate OpenAPI specification files from API code using GitHub Copilot, and register the API to an API center.
API developers can also take advantage of features in the extension to discover and consume APIs in the API center and ensure API governance.
Prerequisites
One or more API centers in your Azure subscription.
- Currently, you need to be assigned the Contributor role or higher permissions to manage APIs with the extension.
The following Visual Studio Code extensions are needed for the specified scenarios:
- GitHub Actions - to register APIs using a CI/CD pipeline with GitHub Actions
- Azure Pipelines - to register APIs using a CI/CD pipeline with Azure Pipelines
- GitHub Copilot - to generate OpenAPI specification files from API code
Setup
Install the Azure API Center extension for Visual Studio Code from the Visual Studio Code Marketplace. Install other extensions as needed.
Note
Where noted, certain features are available only in the Azure API Center extension's pre-release version. When installing the extension from the Visual Studio Code Marketplace, you can choose to install the release version or a pre-release version. Switch between the two versions at any time by using the extension's Manage button context menu in the Extensions view.
In Visual Studio Code, in the Activity Bar on the left, select API Center.
If you're not signed in to your Azure account, select Sign in to Azure..., and follow the prompts to sign in. Select an Azure subscription with the API center (or API centers) you wish to view APIs from. You can also filter on specific subscriptions if you have many to view from.
Register an API - step by step
The following steps register an API in your API center as a one-time operation.
- Use the Ctrl+Shift+P keyboard shortcut to open the Command Palette. Type Azure API Center: Register API and hit Enter.
- Select Manual.
- Select the API center to register APIs with.
- Answer prompts with information including API title, type, version title, version lifecycle, definition title, specification name, and definition file to complete API registration.
The API is added to your API center inventory.
Register APIs - CI/CD pipeline
The following steps register an API in your API center with a CI/CD pipeline. With this option, add a preconfigured GitHub or Azure DevOps pipeline to your active Visual Studio Code workspace that is run as part of a CI/CD workflow on each commit to source control. It's recommended to inventory APIs with your API center using CI/CD to ensure API metadata including specification and version stay current in your API center as the API continues to evolve over time.
- Use the Ctrl+Shift+P keyboard shortcut to open the Command Palette. Type Azure API Center: Register API and hit Enter.
- Select CI/CD.
- Select either GitHub or Azure DevOps, depending on your preferred source control mechanism. A Visual Studio Code workspace must be open for the Azure API Center extension to add a pipeline to your workspace. After the file is added, complete steps documented in the CI/CD pipeline file itself to configure required environment variables and identity. On push to source control, the API is registered in your API center.
Learn more about setting up a GitHub Actions workflow to register APIs with your API center.
Generate OpenAPI specification file from API code
Use the power of GitHub Copilot with the Azure API Center extension for Visual Studio Code to create an OpenAPI specification file from your API code. Right-click on the API code, select Copilot from the options, and select Generate API documentation. GitHub Copilot creates an OpenAPI specification file.
Note
This feature is available in the pre-release version of the API Center extension.
After generating the OpenAPI specification file and checking for accuracy, you can register the API with your API center using the Azure API Center: Register API command.