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:
- You must have an Azure subscription to use this package.
Install the Azure WebSiteManagement client REST client library for JavaScript with npm:
npm install @azure-rest/arm-appserviceTo 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);The following section shows you how to initialize and authenticate your client, then list all of your 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);AI coding tools such as VS Code and GitHub Copilot can help you write and debug code that uses this library. See Using the Azure SDK for JavaScript with AI tools for available integrations.
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.