Converting Data-Api-Builder Config to Static Web App Config
If you are working with the Data API Builder in isolation, but then you decide to combine and publish the Db configuration and the client side (JavaScript files) together on a Static Web App, how do you do it?
The DAB Config file
Let’s consider the SQL database script for this exercise.
I have shrunk it for this example though:
| |
Assuming you have already DAB installed, run the following commands on PowerShell:
| |
The file dab-config.json will be generated, looking like this:
| |
Html and Javascript
If you are running the HTML page on a web server and the API via DAB separately, you will end up with something like this:
File: index.html
| |
NOTE: If the html page is running on port 8000, the CORS origins on
dab-config.jsonneed updating to allow for queries to happen:"origins": ["http://localhost:8000"]. This page sample was originally created by Davide, however as I have tweaked it, it is available asdab-simple-beforeon PlayGoKids repo.
The SWA Database Config file
The SWA Database configuration file is also a DAB configuration file! Let’s have a look, on the same directory run the command:
| |
This will initialize a new SWA config on .\swa-db-connections\staticwebapp.database.config.json. Looking like this:
| |
It has the same structure as a dab configuration file because it is a dab configuration file! With a minor change:
API path
From (when compared to dab-config.json):
| |
To:
| |
NOTE: Ignore the Host mode, as this can be either set to development or production.
Make sure to copy the entities from dab-config.json, and then things should work:
| |
Html and Javascript
Here we can run the Html page and DB configuration together. Before it can happen we need to update the /rest endpoint on Html.
File: index.html
| |
NOTE: In this case, the URL mapping was updated. This page sample was originally created by Davide. This is available as
dab-simple-afteron PlayGoKids repo.
Then we can run the Html page and DB configuration in a single command via SWA CLI:
| |
Both the server and client sides will be running simultaneously in different ports: https://localhost:5001 and http://localhost:4280.

Join the conversation! Share your thoughts and connect with other readers.