Giter Site home page Giter Site logo

devkimchi / api-center-sample Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 163 KB

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

License: MIT License

Bicep 11.90% C# 75.47% HTML 4.65% CSS 5.27% PowerShell 2.71%
asp-net-core azure bicep blazor minimal-api api-center

api-center-sample's Introduction

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

api-center-sample's People

Contributors

justinyoo avatar

Stargazers

jaysonv avatar Pierce Boggan avatar  avatar

Watchers

 avatar  avatar

Forkers

cplemm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.