Code Monkey home page Code Monkey logo

api-management-sample-apis's Introduction

Sample APIs for Azure API Management

This repository is a template for the Azure Developer CLI (azd) that includes several different APIs:

  • Star Wars API - a read-only API about the Star Wars films

    • REST (includes caching demonstration)
    • Synthetic GraphQL
  • Todo List API - a read/write API for storing todo lists.

    • REST
    • GraphQL (pass-through)

Others will be added in the future. For each backend service, the appropriate configuration is added to the Azure API Management instance to handle that API, and logging for the API is handled via Azure App Insights.

Prerequisites

The following prerequisites are required to use this application. Please ensure that you have them all installed locally.

Quick start

The fastest way for you to get this application up and running on Azure is to use the azd up command. This single command will create and configure all necessary Azure resources - including access policies and roles for your account and service-to-service communication with Managed Identities.

  1. Open a terminal, create a new empty folder, and change into it.
  2. Run the following command to initialize the project, provision Azure resources, and deploy the application code.
azd up --template api-management-sample-apis

You will be prompted for the following information:

  • Environment Name: This will be used as a prefix for the resource group that will be created to hold all Azure resources. This name should be unique within your Azure subscription.
  • Azure Location: The Azure location where your resources will be deployed.
  • Azure Subscription: The Azure Subscription where your resources will be deployed.

NOTE: This may take a while to complete as it executes three commands: azd init (initializes environment), azd provision (provisions Azure resources), and azd deploy (deploys application code). You will see a progress indicator as it provisions and deploys your application.

When azd up is complete it will output the URLs for each backend service. You can also access the APIs through a centralized API Management instance.

NOTE:

  • The azd up command will create Azure resources that will incur costs to your Azure subscription. You can clean up those resources manually via the Azure portal or with the azd down command.
  • You can call azd up as many times as you like to both provision and deploy your solution, but you only need to provide the --template parameter the first time you call it to get the code locally. Subsequent azd up calls do not require the template parameter. If you do provide the parameter, all your local source code will be overwritten if you agree to overwrite when prompted.
  • You can always create a new environment with azd env new.

Overriding Service Locations

While most services are available in all regions, you may need to override the location for certain services. The following are supported:

  • appInsightsLocationName for Application Insights.
  • staticSitesLocationName for Static Web Apps.

To override

Application architecture

This application utilizes the following Azure resources:

This template provisions resources to an Azure subscription that you will select upon provisioning them. Please refer to the Pricing calculator for Microsoft Azure and, if needed, update the included Azure resource definitions found in infra/main.bicep to suit your needs.

Application code

The repo is structured to follow the Azure Developer CLI conventions including:

  • Source Code: All application source code is located in the src folder.
  • Infrastructure as Code: All application "infrastructure as code" files are located in the infra folder.
  • Azure Developer Configuration: An azure.yaml file located in the root that ties the application source code to the Azure services defined in your "infrastructure as code" files.
  • VS Code Configuration: All VS Code configuration to run and debug the application is located in the .vscode folder.

Azure Subscription

This template will create infrastructure and deploy code to Azure. If you don't have an Azure Subscription, you can sign up for a free account here. Make sure you have contributor role to the Azure subscription.

Azure Developer CLI - VS Code Extension

The Azure Developer experience includes an Azure Developer CLI VS Code Extension that mirrors all of the Azure Developer CLI commands into the azure.yaml context menu and command palette options. If you are a VS Code user, then we highly recommend installing this extension for the best experience.

Here's how to install it:

VS Code

  1. Click on the "Extensions" tab in VS Code
  2. Search for "Azure Developer CLI" - authored by Microsoft
  3. Click "Install"

Marketplace

  1. Go to the Azure Developer CLI - VS Code Extension page
  2. Click "Install"

Once the extension is installed, you can press F1, and type "Azure Developer CLI" to see all of your available options. You can also right click on your project's azure.yaml file for a list of commands.

Next Steps

At this point, you have a complete application deployed on Azure. But there is much more that the Azure Developer CLI can do. These next steps will introduce you to additional commands that will make creating applications on Azure much easier. Using the Azure Developer CLI, you can setup your pipelines, monitor your application, test and debug locally.

Monitor the application using azd monitor

To help with monitoring applications, the Azure Dev CLI provides a monitor command to help you get to the various Application Insights dashboards.

  • Run the following command to open the "Overview" dashboard:

    azd monitor --overview
  • Live Metrics Dashboard

    Run the following command to open the "Live Metrics" dashboard:

    azd monitor --live
  • Logs Dashboard

    Run the following command to open the "Logs" dashboard:

    azd monitor --logs

Run and Debug Locally

The easiest way to run and debug is to leverage the Azure Developer CLI Visual Studio Code Extension. Refer to this walk-through for more details.

Clean up resources

When you are done, you can delete all the Azure resources created with this template by running the following command:

azd down

api-management-sample-apis's People

Contributors

adrianhall avatar galiniliev avatar jongio avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-management-sample-apis's Issues

Command is wrong in the Readme.md

Describe the issue:
After executing the azd up --template api-management-sample-apis command in Readme, the error unknown flag:--template appears.
image
Suggestion:

  1. Not login before executing the azd command.
    So update azd up --template api-management-sample-apis to
azd auth login
azd init -t api-management-sample-apis
azd up
  1. Command "azd up" not include "azd init", so update Notes to:
The command "azd up" take a while to complete as it executes two commands: azd provision (provisions Azure resources), and azd deploy (deploys application code). You will see a progress indicator as it provisions and deploys your application.

@galiniliev and @hemarina for notification.

Recommend updating appservice.bicep to latest azure-dev files

In the original version of appservice.bicep, appSettings was not wrapped with an @secure decorator, so if a developer put any secrets in their app settings, it would leak into deployment outputs and cause a security alert. The latest version now has the secure decorator.

I noticed this repo is using the old version, so I recommend upgrading if you can.

You can git clone https://github.com/azure/azure-dev and then cp like this:

cp ../azure-dev/templates/common/infra/bicep/core/host/* infra/core/host/.

Or only cp app service files if you don't use other hosts:

cp ../azure-dev/templates/common/infra/bicep/core/host/appservice* infra/core/host/.

Then run azd up to make sure all still works.

Fail to load the URLs for each backend service after executing command "azd up"

Describe the issue:
After executing the azd up command, clicking on the three URLs for each backend service it outputs failed to load.
image
The error is as follows:
image
image
image

Repro steps:

  1. Run command azd auth login.
  2. Run command azd init -t api-management-sample-apis.
  3. Run command azd up.
  4. Click the three URLs for each backend service.

Expected behavior:
The three URLs for each backend service can load successfully.

@galiniliev and @hemarina for notification.

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.