REST

REST

Let’s bind to some REST data. We will be using this publicly available REST source which returns standard JSON data:

https://jsonplaceholder.typicode.com/users

Data[] Block

In the Data[] block we list our data sources. In our example we have only one:

Data:Users =HTTP(https://jsonplaceholder.typicode.com/users)

JSON

JSON is the data source type that we want to use. Data[] blocks can contain various sources just as pages can have varying control types for children.

:Users

Users is the name to assign to our data source.

=HTTP()

In this example we use the short form and a parameter which corresponds to the .Text property. We can specify JSON as a multiline property using the full syntax, but in this case we want to use external data obtained by REST.

To do this, we use data binding and the HTTP tag. The = signifies it is databound, and the URL parameter to the HTTP data binding expression specifies where to obtain the data.

Binding to Data

In our controls properties we use data binding to display data from our JSON data source.

Text =.Users.email

In this example we use full property binding. The .Text property (via parameter) is bound to the .email field of the JSON data source named Users.

The binding starts with a . (period) which is a shortcut for data. These are functionally identical:

=data.Users.email
=.Users.email

Text [b:Name:] [=.Users.name]

In this example we use markdown plus data binding. This is useful to allow data binding in the middle of an expression without binding the entire property.

Data binding in markdown uses the same data binding syntax, just surround it with markdown markers [ and ].

Text [b:City:] [=.Users.address.city]

This binding is the same as the previous, but goes into a sub field in the JSON data.