Skip to content

This provides sample Bicep files, ASP.NET Core Minimal API as server-side API app and Blazor Web app.

License

Notifications You must be signed in to change notification settings

devkimchi/api-center-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure API Center Sample

This provides sample Bicep files, ASP.NET Core Minimal API as server-side API app and Blazor Web app.

Prerequisites

Getting Started

Check the list of available locations

  1. 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
  2. Open ./infra/main.bicep and update the location 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

Provision resources to Azure

  1. Fork this repository to your GitHub account.

  2. 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)"
  3. 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.

  4. 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 APIs to API Center

  1. 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
  2. Register Pet Store API to API Center via Azure Portal by following this document: Register API

  3. 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/*"

Generate API Client from API Center via VS Code

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

Resources