TWebDreamFactoryClientDataset
Introduction
DreamFactory offers REST API
creation without writing code. Via a web interface, the various characteristics of the REST API
you want to create to let your application access data and other services on the back-end, can be configured. As such, you can create a REST API
that can be consumed by a TMS WEB Core web client application. For handling CRUD
operations on data that are exposed by a DreamFactory REST API
, the TWebDreamFactoryClientDataset
is available. The TWebDreamFactoryClientDataset
is the bridge between the REST API
and the DB-aware controls that are used in the web client application.
Configuring your DreamFactory back-end
Download the DreamFactory installer from https://bitnami.com/stack/dreamfactory/installer and install the software. After install, DreamFactory can by default be started via http://127.0.0.1/dreamfactory/dist/index.html#/login
To create a REST API service for a SQLite
database used in the demo, follow these steps
Create the SQLite Service 'tasksdb'
- Select Services on the top menu
- Click Create on the left menu
- Click on "Service Type" dropdown to select Database--SQLite
- Namespace: tasksdb
- Label: Tasks DB Service
- Go to Config tab
- Database: tasks
- Save
Create Schema Table Task
-
Select Schema on the top menu
-
Click on Service dropdown to select "Tasks DB Service". If not visible, click on
Refresh
button next to it or refresh the page. - Click on upload JSON and upload the following JSON code. This will create the table.
{
"resource": [
{
"name": "task",
"label": "Task",
"plural": "Tasks",
"alias": null,
"auto_increment": true,
"is_primary_key": true,
"field": [
{
"name": "id",
"label": "Id",
"type": "id"
},
{
"name": "userid",
"label": "User Id",
"type": "user_id_on_update"
},
{
"name": "status",
"label": "Status",
"type": "string",
"db_type": "nvarchar(80)",
"size": 80,
"allow_null": false
},
{
"name": "descr",
"label": "Description",
"type": "text",
"allow_null": false
},
{
"name": "due_date",
"label": "Due Date",
"type": "date",
"allow_null": false
}
]
}
]
}
Setup CORS
- Select Config on the top menu
- Click CORS on the left menu
- Click the + button
- Path: *
- Click on Methods dropdown to select "All"
- Enabled: ON
- Save
Set up a Role "LoggedIn" to access the “tasksdb” service
- Select Roles on the top menu
- Click Create on the left menu
- Name: LoggedIn
- Active: ON
- Go to Access tab
- Click on + button to add a rule
- Select Service as tasksdb
- Select Component as *
- Select Actions as All
- Click on Show/Hide in the last column "Advanced filters". A Filter set up form appears.Click on + button to its right
- Enter Field as userid
- Leave Operator as =
- Enter Value as {user.id}
- Save
Create App Tasks
- Select Apps on the top menu
- Click Create on the left menu
- Application Name: Tasks
- Click on "Default Role" dropdown to select our role created earlier, "Default"
- Active: ON
- Save
- Copy the API key from the Tasks app, it is required for the TMS WEB Core w.
Set up User service for Open Registration
- Select Services on the top menu
- Click on User service in the list
- Go to Config tab
- Allow Open Registration: ON
- Click on + button to add a Per App Open Reg Role
- Select App as Tasks
- Select Role as LoggedIn
- Click on "Open Reg Email Service" drop down and select the EMPTY value.
- Save
Using DreamFactory via TWebDreamFactoryClientDataset
Drop a TWebDreamFactoryClientDataset component on the form. First set the API key for the use of the DreamFactory REST API. This API key was obtained in the setup step 5 “Create App”. Configure the URL of WebDreamFactoryClientDataset to the URL of the DreamFactory server. When testing on localhost, this is for example 'http://127.0.0.81'. Setup the WebDreamFactoryClientDataset.DBServiceName to the name of the DreamFactory service you created, i.e. for this sample ‘tasksdb’ and set the WebDreamFactoryClientDataset.TableName to the name of the table you want to use for this dataset, i.e. for this sample ‘tasks’ and also set the unique key field name via WebDreamFactoryClientDataset.KeyfieldName. Finally, setup the fields the dataset will use via the WebDreamFactoryClientDataset.FieldDefs.
Reference
These are the properties, methods, events of the TWebDreamFactoryClientDataset component
Properties
Property | Description |
---|---|
Active | Set this to True to activate the DataSet. Field definitions must be present along with other properties described below. |
ApiKey | Sets the DreamFactory unique application secret obtained after creating a collection |
DBServiceName | Sets the name of the service created in DreamFactory for accessing the database |
DreamFactoryURL | Sets the URL for the DreamFactory server |
KeyfieldName | Sets the name of the unique key field in the table |
TableName | Sets the name of the table in DreamFactory to work with as a dataset for user management |
Methods
Property | Description |
---|---|
Login(UserName,Password: string; IsSignup: boolean) | Performs a login on the DreamFactory service. When successful, the data is fetched in the dataset. When IsSignUp is true, a new account is created on the Rad Server instance |
Refresh | Reloads the data from DreamFactory table in the web client dataset |
AddSortFieldDef(aField: string; isAscending: Boolean) | Sets the sort order of data returned from DreamFactory in the dataset |
ClearSortFieldDefs | Clears any previously set sort order |
Events
The TWebDreamFactoryClientDataset
exposes the standard TDataSet
events and is as such similar in functionality. It offers an additional event for handling a signup attempt with an already existing username
Event | Description |
---|---|
OnUserExists(Sender, UserName) | Event triggered when a signup is attempted using a username that already existed. |