Introduction
In today’s data-driven landscape, managing and leveraging APIs effectively is crucial for Data-driven organizations.
Azure Data API Builder emerges as a powerful tool designed to streamline API management, offering robust data integration, security, and performance monitoring features.
This blog provides a comprehensive technical deep dive into Azure Data API Builder, exploring its capabilities, setup process, and best practices for optimal use.
On May 15th, the Data API builder becomes Generally Available.
What is Azure Data API Builder?
Azure Data API Builder is a managed service that simplifies the creation, management, and deployment of APIs. It enables seamless data integration from various sources, allowing IT professionals to build scalable and secure APIs efficiently.
Core Features:
- Seamless integration with Azure-based data sources
- Rapid API Development
- Automated API generation
- Support of REST and GraphQL endpoints
- Security and Access Control
- Scalability and Performance
- Provides insights into API performance and usage
Use Cases and Benefits:
- Enterprise Application
- Microservices Architecture
- MVP or POC – prototype development
- Leveraging Machine Learning using APIs
- Use of API data in Data pipelines
Architecture
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_569/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-1024x569.png)
The architecture of Data API Builder consists of –
- Source data
- Configuration file
- Data API Builder Runtime
- REST and GraphQL methods
- REST and GraphQL endpoints
Setting Up Azure Data API Builder
There are various ways to set up DAB – Local and Azure services. For simplicity, in this blog, we will see how to set it up locally using an MS SQL Server container containing AdventureWorks database backup restored.
Prerequisites
- Docker Desktop
- .Net 8.0
- SQL Server Management Studio or Azure Data Studio
- Sample demo database – AdventureWorks database restored.
- Postman
Install the Data API builder CLI
Install the Microsoft.DataApiBuilder
package from NuGet as a .NET tool.
dotnet tool install --global Microsoft.DataApiBuilder
Setup Local Database
For the simipliticy of this demo, I have created a docker image with MS SQL Server 2022 containing AdventureWorks2022 and AdventureWorksDW2022 database backup restored to be ready for consumption.
docker run -d --name sql-server -p 1433:1433 dominicvivek06/sql-server
The default “sa” password is “sqldev&data2024”
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_981,h_285/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-1.png)
Verify successful connections by connecting to the local database. I am using Azure Data Studio
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_549/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-2-1024x549.png)
Check for the two databases – AdventureWorks2022 and AdventureWorksDW2022 database.
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_380/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-3-1024x380.png)
Setup Configuration files
First, we need to initialize the configuration file –
dab init --database-type "mssql" --host-mode "Development" --connection-string "Server=localhost,1433;User Id=sa;Database=AdventureWorks2022;Password=sqldev&data2024;TrustServerCertificate=True;Encrypt=True;"
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_102/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-5-1024x102.png)
This will create a baseline configuration – dab-config.json
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_456/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-4-1024x456.png)
Let’s start by adding our first entity – AddressType to the configuration using dab utility with add parameter.
dab add AddressType --source "Person.AddressType" --permissions "anonymous:*"
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_204/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-6-1024x204.png)
Let’s add a view as well. Note – adding table and view are different.
dab add vProductAndDescription --source Production.vProductAndDescription --source.type View --source.key-fields "ProductID" --permissions "anonymous:read"
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_160/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-7-1024x160.png)
Start DAB
Now, let’s start the DAB (note – start the dab in a separate terminal and don’t terminate)
dab start
dab start
Information: Microsoft.DataApiBuilder 1.1.7
Information: Config not provided. Trying to get default config based on DAB_ENVIRONMENT...
Information: Environment variable DAB_ENVIRONMENT is (null)
Loading config file from dab-config.json.
Information: Loaded config file: dab-config.json
Information: Setting default minimum LogLevel: Debug for Development mode.
Starting the runtime engine...
Loading config file from dab-config.json.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
User profile is available. Using 'C:\Users\domin\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
[AddressType] REST path: /api/AddressType
info: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
[vProductAndDescription] REST path: /api/vProductAndDescription
dbug: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
Executing query: SELECT STE.type_desc FROM sys.triggers ST inner join sys.trigger_events STE On ST.object_id = STE.object_id AND ST.parent_id = object_id(@param0 + '.' + @param1) WHERE ST.is_disabled = 0;
dbug: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
Executing query: SELECT ifsc.column_name from sys.columns as sc INNER JOIN information_schema.columns as ifsc ON (sc.is_computed = 1 or ifsc.data_type = 'timestamp') AND sc.object_id = object_id(@param0+'.'+@param1) and ifsc.table_name = @param1 AND ifsc.table_schema = @param0 and ifsc.column_name = sc.name;
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Logging primary key information for entity: AddressType.
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Primary key column name: AddressTypeID
Primary key mapped name: AddressTypeID
Type: Int32
IsNullable: False
IsAutoGenerated: True
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Logging primary key information for entity: vProductAndDescription.
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Primary key column name: ProductID
Primary key mapped name: ProductID
Type: Int32
IsNullable: False
IsAutoGenerated: False
info: Azure.DataApiBuilder.Service.Startup[0]
Successfully completed runtime initialization.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\devopsdemo\sql
Look for – “Now listening on: http://localhost:5000” in the startup log. If you see this message, then it means DAB has started successfully.
API Documentation
One of the capabilities of DAB is that it also produces Swagger API docs.
The Swagger API can be accessed by
https://localhost:5000/swagger
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_567/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-17-1024x567.png)
REST API Endpoints
The API endpoint is available at http://localhost:5000/
Verify the status of the API endpoint. The “status”: “Healthy” indicates a successful DAB configuration.
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_444/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-9-1024x444.png)
Let’s view our added table entity – AddressType via API
http://localhost:5000/api/AddressType
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_652/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-10-1024x652.png)
Next, let’s view our added view – vProductAndDescription
http://localhost:5000/api/vProductAndDescription
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_653/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-11-1024x653.png)
Both the listing of entity and view were successful. Now, let’s pass the parameters to verify the API. For that, we provide an ID to the API endpoint.
http://localhost:5000/api/AddressType/AddressTypeID/2
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_703/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-12-1024x703.png)
GraphQL Endpoint
We can also access the GraphQL endpoint via – http://localhost:5000/graphql
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_611/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-13-1024x611.png)
Select “Browse Schema” to view the schema of the API’s.
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_451/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-14-1024x451.png)
We can start browsing for a GraphQL endpoint –
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_409/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-15-1024x409.png)
Getting a particular ID also works in GraphQL
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_257/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-16-1024x257.png)
Cleaning Docker
- Stop the “dab start” window by pressing Ctrl+C.
- Get the docker container by running docker ps
![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1024,h_80/https://www.dominickumar.com/blog/wp-content/uploads/2024/06/image-18-1024x80.png)
3. use docker stop to stop the container
PS D:\devopsdemo\sql> docker stop d6a5317d9b92
d6a5317d9b92
4. Remove the docker image
PS D:\devopsdemo\sql> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dominicvivek06/sql-server latest c543867b9033 28 hours ago 2.81GB
grafana/grafana latest f9095e2f0444 2 weeks ago 443MB
prom/prometheus latest ecb74a3b23a9 3 weeks ago 272MB
containerwatch/containerwatch 1.0.0 800c8dc20716 10 months ago 219MB
PS D:\devopsdemo\sql> docker rmi c543867b9033 -f
Untagged: dominicvivek06/sql-server:latest
Untagged: dominicvivek06/sql-server@sha256:29a4976c2c7251860a17f800c1d02deb478eabb3a229b676c8b2d4d7c6c2cad4
Deleted: sha256:c543867b90337175154f1585fce03be0610d476938782294e5b90b85c3cc17d1
PS D:\devopsdemo\sql>
Full Documentation
For full documentation, visit https://learn.microsoft.com/en-us/azure/data-api-builder/
Conclusion
Azure Data API Builder is a powerful tool that simplifies creating, managing, and securing APIs, offering robust data integration, security, and performance monitoring features. By following the setup process outlined in this blog, you can leverage Azure Data API Builder to optimize your API management and unlock the full potential of your data assets. Whether integrating data from multiple sources, securing sensitive information, or scaling your applications, Azure Data API Builder provides the tools and capabilities you need to succeed in the digital era.
Hope you enjoyed this blog post. Post comments or questions regarding Azure Data API Builder.