Microsoft has released a Data API Builder tool, which will generate both a REST API and a GraphQL API over your database. It works with SQL Server, as well as Azure SQL Database and Cosmos DB. It even supports Postgres and MySQL.
There’s usually a lot of work that goes into creating an API, so I wanted to see how this tool worked and what the end product was like.
Install:
I’m running Windows 11, with the 2025 SQL Server developer preview edition.
First, we’ll need to make sure we have the DotNet SDK installed. You can run this in the command line to see if you have it already installed:
dotnet --version
You’ll get a message “The command could not be loaded…” if you don’t have it.
We can use Winget to install the SDK for version 8 (I got version 8.0.415):
winget install Microsoft.DotNet.SDK.8
Or it can be downloaded here.
Even though there are more current editions available, the current version of Data API Builder wants to run with the Framework version 8.
Once we have the SDK, we can run a DotNet command at the command line to get the Data API Builder (DAB) tool:
dotnet tool install -g Microsoft.DataApiBuilder
Setup:
Now that we have DAB installed, we can get it setup for use.
We’ll need a database for the API backend. I’ve created a simple database with two tables, with some test data added. The script is posted on GitHub. But we can use any database.
Once we have a database to use, we can configure the DAB tool. This will create a configuration file that will define the service. We can run this code in the command line to set everything up (Obviously, you’ll want to update the connection string values to use the correct values for your instance):
dab init --database-type "mssql" --host-mode "Development" --connection-string "Server=localhost\MSSQLSERVER01;User Id=DABTest;Database=DabTest;Password=DABTest;TrustServerCertificate=True;Encrypt=True;"
If there isn’t an issue, you should get a fast response. The output will tell you where the config file was created. My initial run failed, because I had DotNet 9 installed and not 8, so the console didn’t return anything for 20-30 seconds.
You’ll also need to make sure that the SQL Server instance can accept remote connections over TCP/IP.
Next, we need to specify which tables are accessible to DAB. My sample database has two tables, so we’ll make both of those available. With the dab add command, we’ll specify a name for each entity, the table that entity is mapped to, and specify permissions. In our test case, we won’t require any sort of permissions, we’ll grant everyone full access. There are other options, but these are the required ones.
dab add Team --source "dbo.team" --permissions "anonymous:*" dab add Player --source "dbo.player" --permissions "anonymous:*"
You should get a message that the entity was set up.
As long as each table has a primary key, the generated API will allow us to look up individual records using those key values.
Running and Calling the API:
We’ll start the API with this command
dab start
If everything starts successfully, you’ll see several messages, including one for the URL for the API:
Now listening on: http://localhost:5000
The message will also give us the path to each entity:
[Team] REST path: /api/Team
[Player] REST path: /api/Player
DAB will automatically generate some API documentation for us. We can see it at:
http://localhost:5000/swagger
This will let us know how we can retrieve and manipulate our data.
We’ll try calling the API to read data. For this, we can just make calls in the web browser. Of course, you can use whatever tool to normally use for REST calls (CURL, Postman, etc.). I like the Advanced Rest Client.
Let’s try to return all of the teams. We can call this URL:
http://localhost:5000/api/Team
We’ll get back a JSON document with all of our team data:
{
"value": [
{
"TeamId": 1,
"TeamName": "Atlanta",
"TeamNickName": "Falcons"
},
{
"TeamId": 2,
"TeamName": "Carolina",
"TeamNickName": "Panthers"
},
{
"TeamId": 3,
"TeamName": "New Orleans",
"TeamNickName": "Saints"
},
{
"TeamId": 4,
"TeamName": "Tampa Bay",
"TeamNickName": "Buccaneers"
}
]
}
We can also just select one record:
http://localhost:5000/api/Team/TeamId/1
{
"value": [
{
"TeamId": 1,
"TeamName": "Atlanta",
"TeamNickName": "Falcons"
}
]
}
Once we’re done, we can press Control + C at the command line to stop the service.
Next Steps:
This barely touches on the functionality available in this tool. We can also add, update, and remove data, along with reading it. There’s also the GraphQL API available. There are also a lot of configuration options available. We would need to take advantage of those to tighten security, if we wanted to make the APIs available to others.
Links: