An Azure service that provides streamlined full-stack web app development.
Data API Builder (DAB) is integrated into Azure Static Web Apps through the database connection feature. Once configured, the static web app exposes DAB-powered endpoints under the /data-api path, which the front-end calls like any other HTTP API.
High-level flow:
- Configure a database connection for the Static Web App (in Azure Portal and via config file).
- Static Web Apps hosts DAB for that app.
- The front-end calls
/data-api/rest/...or/data-api/graphqlon the same domain.
1. How DAB integrates with Static Web Apps
Static Web Apps uses Data API Builder under the hood:
- It takes REST/GraphQL requests and converts them into database queries.
- It uses the same authentication/authorization model as Static Web Apps (roles, etc.).
From the overview:
- Database connections “allow access to a database from your static web app without writing custom server-side code.”
- Requests are routed as:
-
example.com/api/*→ Functions -
example.com/data-api/*→ DAB database endpoints (REST/GraphQL) -
example.com/*→ Static content
-
The /data-api prefix is fixed and cannot be changed. You can configure only the suffixes, such as rest and graphql.
2. Configuration pieces
There are two required steps:
- Connect the database in Azure Portal
- In the Static Web App resource, add a Database connection and point it to PostgreSQL (or other supported DB).
- This step wires the Static Web App to the database and ensures the runtime overwrites the connection string at deployment.
- Add
staticwebapp.database.config.jsonto the repo- This is the DAB configuration file. A sample is described in the database configuration docs.
- Key sections:
-
data-source: database type (postgresql,mssql,mysql,cosmosdb_nosql) and connection string placeholder. -
runtime: defines REST and GraphQL endpoints and CORS for local dev. -
entities: maps URL paths/types to database tables and defines permissions.
-
Example behaviors from the docs:
- Database connection: In development, the runtime reads the connection string from the config file (typically via
@env('DATABASE_CONNECTION_STRING')). In production, Static Web Apps overwrites this with the connection info collected when the database is connected. - API endpoint: REST is available at
/data-api/restand GraphQL at/data-api/graphqlby default. The suffixes (rest,graphql) are configurable, but/data-apiis not. - API security:
runtime.host.corsdefines allowed origins (for local dev, usuallyhttp://localhost:4280). - Entities: Define which tables are exposed and under what names, and how they are secured with roles.
The Static Web Apps CLI can generate a stub config:
swa db init --database-type postgresql
This creates staticwebapp.database.config.json in swa-db-connections by default.
3. How the static web app calls DAB
Once the database connection and config file are in place and deployed:
- The front-end (JavaScript, etc.) calls the DAB endpoints on the same origin:
- REST:
https://<your-app>.azurestaticapps.net/data-api/rest/... - GraphQL:
https://<your-app>.azurestaticapps.net/data-api/graphql
- REST:
- The exact REST paths depend on the
entitiesconfiguration. For example, if an entityPersonis defined, a typical REST path would be:-
GET /data-api/rest/Person -
POST /data-api/rest/Person - etc.
-
- Authentication and roles from Static Web Apps are applied automatically to these endpoints, based on the
permissionsdefined per entity.
In local development with the SWA CLI:
- Start the app with:
swa start ./src --data-api-location swa-db-connections - The CLI exposes
/data-apionhttp://localhost:4280, proxying to the local DAB runtime. - The front-end calls
http://localhost:4280/data-api/rest/...or/data-api/graphqlin the same way it would in production.
4. Summary
- DAB is not a separate service that must be hosted manually; it is provided by Static Web Apps when a database connection is configured.
- Integration is via the
staticwebapp.database.config.jsonfile plus the database connection in the portal. - The static web app calls DAB through
/data-api/restor/data-api/graphqlon the same domain, using paths and permissions defined in theentitiessection.
References:
- Connecting to a database with Azure Static Web Apps (preview)
- Database connection configuration in Azure Static Web Apps (preview)
- Tutorial: Add a PostgreSQL database connection in Azure Static Web Apps (preview) (static-web-apps-rest)
- Tutorial: Add a PostgreSQL database connection in Azure Static Web Apps (preview) (static-web-apps-graphql)
- Tutorial: Add a MySQL database connection in Azure Static Web Apps (preview) (static-web-apps-rest)
- Tutorial: Add an Azure SQL database connection in Azure Static Web Apps (preview) (static-web-apps-rest)
- Tutorial: Add an Azure SQL database connection in Azure Static Web Apps (preview) (static-web-apps-graphql)