This repository contains scripts and configuration files for deploying a Data API Builder instance on Azure App Service with SQL Server and Azure Storage integration.
As of September 2024, the database connection for Azure Static Web Apps is still in preview, which made it unfit for my use case. So I developed this script.
However, I also recommend considering Azure Container Apps, which I prefer as a more scalable and robust solution.
Data API Builder (DAB) is a powerful, cross-platform tool that simplifies the creation of APIs for database operations. It replaces custom CRUD APIs with a zero-code, configuration-based approach. Key features include:
- Support for multiple backend data sources (SQL Server, Azure SQL, Cosmos DB, PostgreSQL, MySQL)
- Automatic generation of REST and GraphQL endpoints
- Native OpenAPI and Swagger support
- Flexible security with EasyAuth, Microsoft Entra Identity, or custom JWT servers
- Seamless integration with Azure services (Static Web Apps, Container Apps, etc.)
- Granular security controls and policy engine
- In-memory caching and OData-like query support for REST endpoints
- Nested Create statements within single transactions for GraphQL
DAB significantly reduces codebase size, eliminates many unit tests, shortens CI/CD pipelines, and introduces advanced capabilities typically reserved for large development teams. It's designed to be simple, scalable, and observable, making it an excellent choice for developers looking to streamline their API development process.
dab-config.json
: Configuration file for Data API BuilderrunScript.ps1
: Main PowerShell script for deploying resourcesupload-config.ps1
: Script for uploading the config file to Azure Blob StoragecreateTable.ps1
: Script for creating tables in the SQL databaseAppServiceDataApiBuilder.bicep
: Bicep template for Azure resource deployment
- Azure CLI
- PowerShell (version 5.1 or later)
- An active Azure subscription
-
Ensure you have Azure CLI and PowerShell installed on your system.
-
Clone this repository and navigate to the directory:
git clone https://github.com/JuanMeeske/AppServiceForContainers-DAB.git cd AppServiceForContainers-DAB
-
Log in to your Azure account:
az login
-
Set the context to the subscription you want to use:
az account set --subscription "Your-Subscription-Name-or-ID"
-
Run the deployment script:
./runScript.ps1
This script will create the necessary Azure resources and deploy the Data API Builder.
Post deployment the script wil try to reach the deployed API. This takes a while because the App Service for Containers needs to start, and this takes some time. You will see something that looks like:
Attempting to reach the API at http://mydabapi-uksouth-wjbf123.azurewebsites.net/swagger for 5 minutes...
Failed to reach the API at 09:20:11. Retrying...
Failed to reach the API at 09:20:41. Retrying...
Failed to reach the API at 09:21:11. Retrying...
Successfully reached the API at 09:21:39
The runScript.ps1
script performs the following actions:
- Creates a resource group
- Deploys Azure resources using the Bicep template
- Creates database tables
- Uploads the Data API Builder configuration to Azure Blob Storage
- Azure App Service with Data API Builder container
- Azure SQL Server and Database
- Azure Storage Account
- Virtual Network with proper configurations
The dab-config.json
file defines the Data API Builder configuration, including database connection, REST and GraphQL endpoints, and entity definitions.
For comprehensive information on Data API Builder, refer to the official Microsoft documentation:
- Data API Builder Overview
- Quickstart: Create and query a REST API
- Quickstart: Create and query a GraphQL API
- Data API Builder CLI reference
- Configuration file reference
- REST API reference
- GraphQL API reference
- Security and authentication
Feel free to submit issues or pull requests if you have suggestions for improvements or encounter any problems. For additional resources, tutorials, and best practices, my website jmsk.io.
MIT License