3

I am trying to create an API App in Azure App Service with PowerShell.

The cmdlet I am calling always create a Web App by default. If it is possible, I would like to know how I can specify the type/kind to be Api App instead of Web App?

New-AzureRmWebApp -Name $name -Location $location -AppServicePlan $plan -ResourceGroupName $resourceGroup

From my reading there is not much different between both except the icon, is it worth it to set the type to "Api App" if it's what my app is all about?

I am using version 5.4.0 of AzureRM PowerShell module.

> Get-Module "AzureRM"

ModuleType Version    Name                                                 
---------- -------    ----
Script     5.4.0      AzureRM
vinhent
  • 2,692
  • 4
  • 17
  • 20

2 Answers2

6

Just call New-AzureRmResource instead and pass in -Kind 'api':

# CREATE "just-an-api" API App

$ResourceLocation = "West US"
$ResourceName = "just-an-api"
$ResourceGroupName = "demo"
$PropertiesObject = @{
    # serverFarmId points to the App Service Plan resource id
    serverFarmId = "/subscriptions/SUBSCRIPTION-GUID/resourceGroups/demo/providers/Microsoft.Web/serverfarms/plan1"
}

New-AzureRmResource -Location $ResourceLocation `
    -PropertyObject $PropertiesObject `
    -ResourceGroupName $ResourceGroupName `
    -ResourceType Microsoft.Web/sites `
    -ResourceName "just-an-api/$ResourceName" `
    -Kind 'api' `
    -ApiVersion 2016-08-01 -Force

..which produces an API App, a Microsoft.Web/sites resource type of the api kind: Portal screenshot

Hold on.. How did you come up with this stuff?

Visit https://resources.azure.com and navigate to an existing API App, build the PowerShell syntax by combining the PowerShell tab with the desired values from the JSON resource definition.

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • Whoops, i put the `kind` property in the wrong place. Fixed! It's part of the parameters not the property bag. My bad. – evilSnobu Mar 16 '18 at 21:29
  • Is it also possible to specify the App Service Plan for the new API app? I thought maybe the name portion in front of the slash would allow you to specify the plan name (similar to dbserver/dbname) but it keeps making a new App Service Plan named Default1 each time. The -ResourceName "just-an-api/$ResourceName" in your example behaves the same as -ResourceName "$ResourceName" from what my testing shows. The name portion following the slash is just ignored. – Kris Nov 21 '18 at 22:10
  • There's a `-Plan` parameter for that. Use `Get-Help New-AzureRmResource -Full`. – evilSnobu Nov 22 '18 at 06:56
  • @evilSnobu thank you for your comment. I did see the Plan parameter and the description is that it is a hash table: "A hash table that represents resource plan properties." So this isn't a simple string which accepts the name of the App Service Plan and I am confused on how I would represent an App Service Plan as a hash table. I cannot find any examples on the web that show how or when this parameter is to be used. I assumed this was not the correct parameter to use. Do you know how to represent an App Service Plan as a hash table which I can pass to this parameter? Thanks for your help! – Kris Nov 22 '18 at 20:03
  • You're completely right. I got a little carried away and didn't test that. Yes, it is indeed a hashtable but `-Plan` is not what you need (my bad). `Plan` is a very misleading parameter name which isn't related to App Service Plans at all. Instead use `serverFarmId` in the property bag. See my updated answer. – evilSnobu Nov 23 '18 at 11:50
  • Yes that is exactly what is needed - it worked perfectly! Thank you very much for your help! – Kris Nov 23 '18 at 17:03
0

There is not a parameter in New-AzureRmWebApp supported to explicitly indicate whether API App or Web App. The resource provider is still Microsoft.Web. And there is no parameter which indicates the type in ARM template.

These two types technically still work in the same way. The difference would be the purpose, icon, OS running choice and debugging capability (refer here What is the difference between an API App and a Web App?).

You may want to classify between the two types by tagging it, which would help manage in case your resource groups have many web resources.

enter image description here

You can create API App via Azure Portal, or Visual Studio.

Also, look at Azure API Management for more flexibility of API wrapping instead of Azure App Service.

EagleDev
  • 1,754
  • 2
  • 11
  • 31