This provides sample Bicep files, ASP.NET Core Minimal API as server-side API app and Blazor Web app.
- .NET SDK 8 or later
- Visual Studio Code with the extensions:
- Azure Developer CLI
- Azure CLI with the extensions:
-
Run the following command to check the list of available locations for API Center.
# Bash az provider show \ -n Microsoft.ApiCenter \ --query "sort(resourceTypes[?resourceType=='services'] | [0].locations[? !(ends_with(@, 'EUAP'))])" | \ jq '[.[] | ascii_downcase | sub(" "; ""; "i")]' # PowerShell az provider show ` -n Microsoft.ApiCenter ` --query "sort(resourceTypes[?resourceType=='services'] | [0].locations[? !(ends_with(@, 'EUAP'))])" | ` ConvertFrom-Json | ForEach-Object { $_.ToLowerInvariant().Replace(" ", "") } | ConvertTo-Json
-
Open
./infra/main.bicep
and update thelocation
parameter with the desired locations.// Update the list of locations if necessary, after comparing to the result above. @allowed([ 'australiaeast' 'centralindia' 'eastus' 'uksouth' 'westeurope' ]) param location string
-
Fork this repository to your GitHub account.
-
Run the commands below to set up a resource names:
# Bash AZURE_ENV_NAME="sample$RANDOM" # PowerShell $AZURE_ENV_NAME="sample$(Get-Random -Min 1000 -Max 9999)"
-
Run the commands below to provision Azure resources:
azd auth login azd init -e $AZURE_ENV_NAME azd up
Note: You may be asked to enter your Azure subscription and desired location to provision resources.
-
Add the USPTO API to API Management.
# Bash az apim api import \ -g "rg-$AZURE_ENV_NAME" \ -n "apim-$AZURE_ENV_NAME" \ --path uspto \ --specification-format OpenAPI \ --specification-path ./infra/uspto.yaml \ --api-id uspto \ --api-type http \ --display-name "USPTO Dataset API" az apim product api add \ -g "rg-$AZURE_ENV_NAME" \ -n "apim-$AZURE_ENV_NAME" \ --product-id default \ --api-id uspto # PowerShell az apim api import ` -g "rg-$AZURE_ENV_NAME" ` -n "apim-$AZURE_ENV_NAME" ` --path uspto ` --specification-format OpenAPI ` --specification-path ./infra/uspto.yaml ` --api-id uspto ` --api-type http ` --display-name "USPTO Dataset API" az apim product api add ` -g "rg-$AZURE_ENV_NAME" ` -n "apim-$AZURE_ENV_NAME" ` --product-id default ` --api-id uspto
-
Register Weather Forecast API to API Center via Azure CLI.
# Bash az apic api register \ -g "rg-$AZURE_ENV_NAME" \ -s "apic-$AZURE_ENV_NAME" \ --api-location ./infra/weather-forecast.json # PowerShell az apic api register ` -g "rg-$AZURE_ENV_NAME" ` -s "apic-$AZURE_ENV_NAME" ` --api-location ./infra/weather-forecast.json
-
Register Pet Store API to API Center via Azure Portal by following this document: Register API
-
Import the USPTO API from APIM to API Center via Azure CLI.
# Bash APIC_PRINCIPAL_ID=$(az apic service show \ -g "rg-$AZURE_ENV_NAME" \ -s "apic-$AZURE_ENV_NAME" \ --query "identity.principalId" -o tsv) APIM_RESOURCE_ID=$(az apim show \ -g "rg-$AZURE_ENV_NAME" \ -n "apim-$AZURE_ENV_NAME" \ --query "id" -o tsv) az role assignment create \ --role "API Management Service Reader Role" \ --assignee-object-id $APIC_PRINCIPAL_ID \ --assignee-principal-type ServicePrincipal \ --scope $APIM_RESOURCE_ID az apic service import-from-apim \ -g "rg-$AZURE_ENV_NAME" \ -s "apic-$AZURE_ENV_NAME" \ --source-resource-ids "$APIM_RESOURCE_ID/apis/*" # PowerShell $APIC_PRINCIPAL_ID = az apic service show ` -g "rg-$AZURE_ENV_NAME" ` -s "apic-$AZURE_ENV_NAME" ` --query "identity.principalId" -o tsv $APIM_RESOURCE_ID = az apim show ` -g "rg-$AZURE_ENV_NAME" ` -n "apim-$AZURE_ENV_NAME" ` --query "id" -o tsv az role assignment create ` --role "API Management Service Reader Role" ` --assignee-object-id $APIC_PRINCIPAL_ID ` --assignee-principal-type ServicePrincipal ` --scope $APIM_RESOURCE_ID az apic service import-from-apim ` -g "rg-$AZURE_ENV_NAME" ` -s "apic-$AZURE_ENV_NAME" ` --source-resource-ids "$APIM_RESOURCE_ID/apis/*"
You can generate the API client from the API Center extension in Visual Studio Code by following this blog post: Azure API Center: The First Look