Data mocking methods
Last updated
Last updated
© 2024 UI Bakery
The simplest way to mock data is to create an action of JavaScript Code type, that will return the needed JSON object. For instance, if your API/DB table lists cars, you can do it in the following way:
The action can be then referenced in different UI Bakery fields using standard {{actions.newAction.data}}
approach.
If you would also like to emulate the latency when requesting your data source, you can use Promises and setTimeout to return your data. For instance, your JS action can have the following code:
One of the major benefits of using JavaScript Code action step is that you can easily replace your action with real data by simply changing the action type when you connect a real data source.
State variables are a great way of mocking data when you not only want to mock reading data but also writing. Find out more about state variables:
StateSQL databases are often the data sources that people are most reluctant to expose publicly. Fortunately, Google spreadsheets function in a manner very similar to SQL databases within UI Bakery. This allows you to conveniently create a spreadsheet, where each sheet can be considered a table, and the cells in the first row can act as SQL columns:
After the spreadsheet is created, you can connect it as a data source and create actions to retrieve and write data to it.
JSON-Server is an npm package that you can run locally or on a remote server which provides a simple interface to create fake JSON API. You can create Mock API in three easy steps:
Install JSON-server package: \
Create db.json
file with similar format:\
Run JSON server:\
Don't forget that you can always use UI Bakery's Test data sources which are available right in the Data Source connect dialog:
When your data sources are only accessible from a local network, you can also install UI Bakery's self-hosted version and access it from there. UI Bakery self-hosted is easy to install and run, check it out 👇
UI Bakery on-premiseNgRok is a product that creates a secure tunnel from your data source to the internet. Learn more 👇
Connecting local database via ngrok