Load external data into your app
In this guide, you'll build upon your knowledge of binding expression and functions to load data from your own external API or database, unlocking more capabilities built on your existing infrastructure.
You can load data from nearly any external data source into Dynaboard and build apps on it with ease.
Overview
The general process is always the same:
- Start by creating a Function
- Configure your function with the appropriate Resource and props
- Create a binding from your display component to the function's
data
property
Example: Hacker News REST API
The Hacker News API (opens in a new tab) is a RESTful web API powering Hacker News (the orange site). It's a great starting point because it does not require authorization.
An example URL looks like this:
https://hacker-news.firebaseio.com/v0/item/8863.json
And returns a response that looks like this:
{
"by" : "dhouston",
"descendants" : 71,
"id" : 8863,
"kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ],
"score" : 111,
"time" : 1175714200,
"title" : "My YC app: Dropbox - Throw away your USB drive",
"type" : "story",
"url" : "http://www.getdropbox.com/u/2/screencast.html"
}
We're going to query for an item by ID and display its title.
Step 1: Setting up the resource
- Create a Page Function
- In the inspector, click the Resource dropdown and select API Integrations » REST API
- You will be jumped to the new
http1
resource on the Resources2 panel - Under Base URL, enter
https://hacker-news.firebaseio.com/v0
- Click Test Connection and verify that the toast at the bottom of the screen says that the connection was successful
You should use the most common "base URL" of your REST API when setting up a resource. Doing so will allow you to use multiple functions (requests or queries) on the same shared resource configuration without repeating yourself.
Testing a REST API will issue a GET request to the base URL you have specified. It expects a 2xx
response code.
Step 2: Configuring the function
- In the toast at the bottom, click Go Back, or navigate back to
function1
on your page - In Path, enter
/item/8863.json
- Click Test Function to get a preview of the JSON response in the Result panel
- Click Save Function
- Configure the function to run On Page Load by enabling that flag
The result value will be available within the editor via function1.data
.
Step 3: Wiring up the text component
- Drag out a Text component
- In Value, enter:
@{{ function1.data?.by }}: {{ function1.data?.title ?? function1.data?.text }}
This will format the text like so: @dhouston: My YC app: Dropbox - Throw away your USB drive
Curious what the ??
and ?.
above means? They're called nullish coalescing (opens in a new tab) and optional chaining (opens in a new tab), respectively. They are useful here because function1.data
starts off as undefined
on page load, and so accessing by
, title
, and text
would throw an error otherwise.
Step 4: Automatically running functions
Use caution when configuring your functions to run automatically. Avoid having reactive functions with side effects, and instead prefer safe GET / query-like functions. When in doubt, it is best to run your functions explicitly When Called based on event handlers.
Sometimes you want to run a function whenever an input changes, just like you can do with binding expressions in components. Dynaboard refers to these functions as Reactive.
Below, we will extend the Hacker News micro-app above to incorporate a reactive function which runs automatically whenever an input containing the story ID changes.
- Insert an input component from the toolbar
- Click back to
function1
- Replace Path with
/item/{{ input1.value }}.json
- In the Run panel, select Automatically
- Set Limiter to
Debounce
and Limiter Timing to500ms
- Click Save & Run Function
Dynaboard will automatically run your function whenever the input changes, debouncing after 500 milliseconds. Try using the Interact mode to enter 8863
into the input component.
Example: SQL databases
Dynaboard building apps on top of common external SQL databases. So, even if your app doesn't have a finalized API yet, you can still get your data into Dynaboard.
- Configure your SQL resource (e.g. PostgreSQL)
- Create a page function for the resource with your Query of choice (binding expressions supported)
- Bind a Data Table or Chart to the function (e.g.
{{ yourQueryFn.data }}
)
Example queries (PostgreSQL-like)
All ANSI SQL is supported (SELECT
, UPDATE
, INSERT
, etc).
-- select the user's row based on the value in idInput
SELECT *
FROM users
WHERE id = {{ idInput.value }}
LIMIT 1
-- insert a comment
INSERT INTO comment (comment_body)
VALUES ({{ commentBody.value }})
RETURNING *
Make sure the SQL user you configure for your resource has the minimum permissions needed to accomplish the task at hand. That means if you want a read-only user, they should have SELECT
access exclusively.
Supported SQL Resources
- PostgreSQL (also supports CockroachDB)
- MySQL (also supports PlanetScale)
- BigQuery
All available resources
Dynaboard supports a wide range of integrations with other common data sources. Below you can find a catalog of all resources currently supported:
Can't find the resource you're looking for? Drop us a line and we'll put our heads together to figure out how to get your data into Dynaboard.
- AWS S3
- Airtable
- Amplitude
- BigQuery
- Browser
- Facebook Authentication
- Firebase
- GitHub Authentication
- Google Authentication
- Google Sheets
- GraphQL
- Image Transformation
- K/V Store
- Microsoft Authentication
- MongoDB
- MySQL
- Notion
- Okta Authentication
- One Time PIN Authentication
- OpenAPI
- OpenID Connect
- PostgreSQL
- Python Server
- REST API
- Scheduler
- SendGrid
- TypeScript Client
- TypeScript Server
- User Session
- Web3 Client
- Web3 Server
- WebSocket
- Webhook Endpoint