Share via


Azure WebSitemManagement REST client library for JavaScript - version 1.0.0-beta.2

App Service Client

If you are not familiar with our REST client, please spend 5 minutes to take a look at our REST client docs to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api

Key links:

Getting started

Currently supported environments

Prerequisites

Install the @azure-rest/arm-appservice package

Install the Azure WebSiteManagement client REST client library for JavaScript with npm:

npm install @azure-rest/arm-appservice

Create and authenticate a WebSiteManagementClient

To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.

To authenticate with AAD, you must first npm install @azure/identity

After setup, you can choose which type of credential from @azure/identity to use. As an example, DefaultAzureCredential can be used to authenticate the client:

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

Use the returned token credential to authenticate the client:

import WebSiteManagementClient from "@azure-rest/arm-appservice";
import { DefaultAzureCredential } from "@azure/identity";

const client = WebSiteManagementClient(new DefaultAzureCredential());

For browser environments, use the InteractiveBrowserCredential from the @azure/identity package to authenticate.

import { InteractiveBrowserCredential } from "@azure/identity";
import WebSiteManagementClient from "@azure-rest/arm-appservice";

const credential = new InteractiveBrowserCredential({
  tenantId: "<YOUR_TENANT_ID>",
  clientId: "<YOUR_CLIENT_ID>",
});
const client = WebSiteManagementClient(credential);

Examples

The following section shows you how to initialize and authenticate your client, then list all of your App Service Plans.

List All App Service Plans

import { DefaultAzureCredential } from "@azure/identity";
import WebSiteManagementClient, { paginate } from "@azure-rest/arm-appservice";

const subscriptionId = process.env.SUBSCRIPTION_ID as string;
const credential = new DefaultAzureCredential();
const client = WebSiteManagementClient(credential);

const result = [];
const initialResposne = await client
  .path("/subscriptions/{subscriptionId}/providers/Microsoft.Web/serverfarms", subscriptionId)
  .get();
const res = paginate(client, initialResposne);

for await (const item of res) {
  result.push(item);
}

console.log(result);

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.