Quickstart: Use Data API builder with Azure Cosmos DB for NoSQL and Azure Static Web Apps

In this quickstart, you deploy Data API builder (DAB) as a Docker container to Azure Container Apps. You use an Azure Developer CLI (AZD) template to deploy DAB along with an Azure Cosmos DB for NoSQL database using the latest best practices. The template also deploys a sample web application that connects to the DAB endpoint using GraphQL.

Prerequisites

  • Azure Developer CLI
  • .NET 9.0

If you don't have an Azure account, create a free account before you begin.

Initialize the project

Use the Azure Developer CLI (azd) to create an Azure Cosmos DB for NoSQL account, deploy DAB as a containerized solution, and deploy a containerized sample application. The sample application uses DAB to query sample data.

  1. Open a terminal in an empty directory.

  2. If you're not already authenticated, authenticate to the Azure Developer CLI using azd auth login. Follow the steps specified by the tool to authenticate to the CLI using your preferred Azure credentials.

    azd auth login
    
  3. Use azd init to initialize the project.

    azd init --template dab-azure-cosmos-db-nosql-quickstart
    
  4. During initialization, configure a unique environment name.

  5. Deploy the full solution to Azure using azd up. The Bicep templates deploy an Azure Cosmos DB for NoSQL account DAB to Azure Container Apps, and a sample web application.

    azd up
    
  6. During the provisioning process, select your subscription and desired location. Wait for the provisioning process to complete. The process can take approximately seven minutes.

  7. Once the provisioning of your Azure resources is done, a URL to the running web application is included in the output.

    Deploying services (azd deploy)
    
    (✓) Done: Deploying service api
    - Endpoint: <https://[container-app-sub-domain].azurecontainerapps.io>
    
    (✓) Done: Deploying service web
    - Endpoint: <https://[container-app-sub-domain].azurecontainerapps.io>
    
    SUCCESS: Your up workflow to provision and deploy to Azure completed in 7 minutes 0 seconds.
    
  8. Record the values for the URL of the api and web services. You use these values later in this guide.

Configure the database connection

Now, browse to each containerized application in Azure Container Apps to validate that they're working as expected.

  1. First, navigate to the URL for the api service. This URL links to the running DAB instance.

  2. Observe the JSON output from DAB. It should indicate that the DAB container is running and the status is healthy.

    {
      "status": "healthy",
      "version": "1.1.7",
      "app-name": "dab_oss_1.1.7"
    }
    
  3. Navigate to the relative /graphql path for the DAB instance. This URL should open the Nitro GraphQL integrated development environment (IDE).

  4. In the Nitro IDE, create a new document and run this query to get all 100 items in the Azure Cosmos DB for NoSQL products container.

    query {
      products {
        items {
        id
        name
        description
        sku
        price
        cost
        }
      }
    }
    
  5. Finally, navigate to the URL for the web service. This URL links to the running sample web application that connects to the GraphQL endpoint you accessed in the previous step.

  6. Observe the running web application and review the output data.

    Screenshot of the running web application on Azure Container Apps.

Clean up

When you no longer need the sample application or resources, remove the corresponding deployment and all resources.

  1. Remove the deployment from your Azure subscription.

    azd down
    
  2. Delete the running codespace to maximize your storage and core entitlements if you're using GitHub Codespaces.

Next step