Muokkaa

Jaa


Discover and consume APIs with the Azure API Center extension for Visual Studio Code

API developers in your organization can discover and consume APIs in your API center by using the Azure API Center extension for Visual Studio Code. The extension provides the following features:

  • Discover APIs - Browse the APIs in your API center, and view their details and documentation.

  • Consume APIs - Generate API SDK clients in their favorite language including JavaScript, TypeScript, .NET, Python, and Java, using the Microsoft Kiota engine that generates SDKs for Microsoft Graph, GitHub, and more.

API developers can also take advantage of features in the extension to register APIs in the API center and ensure API governance.

Tip

If you want enterprise app developers to discover APIs in a centralized location, optionally enable a platform API catalog for your API center in Visual Studio Code. The platform API catalog is a read-only view of the API inventory.

Prerequisites

Setup

  1. 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.

  2. In Visual Studio Code, in the Activity Bar on the left, select API Center.

    Screenshot of API Center extension in the activity bar.

  3. 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.

Discover APIs

API center resources appear in the tree view on the left-hand side. Expand an API center resource to see APIs, versions, definitions, environments, and deployments.

Screenshot of API Center tree view in Visual Studio Code.

Search for APIs within an API Center by using the search icon shown in the Apis tree view item.

View API documentation

You can view the documentation for an API definition in your API center and try API operations. This feature is only available for OpenAPI-based APIs in your API center.

  1. Expand the API Center tree view to show an API definition.

  2. Right-click on the definition, and select Open API Documentation. A new tab appears with the Swagger UI for the API definition.

    Screenshot of API documentation in Visual Studio Code.

  3. To try the API, select an endpoint, select Try it out, enter required parameters, and select Execute.

    Note

    Depending on the API, you might need to provide authorization credentials or an API key to try the API.

    Tip

    Using the pre-release version of the extension, you can generate API documentation in Markdown, a format that's easy to maintain and share with end users. Right-click on the definition, and select Generate Markdown.

Generate HTTP file

You can view a .http file based on the API definition in your API center. If the REST Client extension is installed, you can make requests directory from the Visual Studio Code editor. This feature is only available for OpenAPI-based APIs in your API center.

  1. Expand the API Center tree view to show an API definition.

  2. Right-click on the definition, and select Generate HTTP File. A new tab appears that renders a .http document populated by the API specification.

    Screenshot of generating a .http file in Visual Studio Code.

  3. To make a request, select an endpoint, and select Send Request.

    Note

    Depending on the API, you might need to provide authorization credentials or an API key to make the request.

Generate API client

Use the Microsoft Kiota extension to generate an API client for your favorite language. This feature is only available for OpenAPI-based APIs in your API center.

  1. Expand the API Center tree view to show an API definition.
  2. Right-click on the definition, and select Generate API Client. The Kiota OpenAPI Generator pane appears.
  3. Select the API endpoints and HTTP operations you wish to include in your SDKs.
  4. Select Generate API client.
    1. Enter configuration details about the SDK name, namespace, and output directory.

    2. Select the language for the generated SDK.

      Screenshot of Kiota OpenAPI Explorer in Visual Studio Code.

The client is generated.

For details on using the Kiota extension, see Microsoft Kiota extension for Visual Studio Code.

Export API specification

You can export an API specification from a definition and then download it as a file.

To export a specification in the extension's tree view:

  1. Expand the API Center tree view to show an API definition.

  2. Right-click on the definition, and select Export API Specification Document. A new tab appears that renders an API specification document.

    Screenshot of exporting API specification in Visual Studio Code.

You can also export a specification using the Command Palette:

  1. Type the Ctrl+Shift+P keyboard shortcut to open the Command Palette.
  2. Select Azure API Center: Export API Specification Document.
  3. Make selections to navigate to an API definition. A new tab appears that renders an API specification document.