REST Bindings Example
Using bindings in a REST query
Last updated
Using bindings in a REST query
Last updated
Use bindings to supply additional information to a query at runtime. In this example we have
An API endpoint that accepts a status field to filter a list of applications
A query named applications
An application that supplies data to the bindings of the query
We can create a binding named status
with a default value of all
.
Using handlebars the binding can be referenced throughout the query in the following places:
URL
Params
Headers
Body
Transformer
The binding can be used as the value of a param of the same name. While the name can be shared it is not required.
The binding can be used as the value of a header of the same name. As above the binding and header name may or may not be shared.
The binding can be used in any part of the request body. e.g. as the value of a json field.
In our application we have the following structure:
The form that will hold the value of our selected status. This is the top level component so that the value can be accessed by components nested underneath.
Type: Create
While this form does not create anything, this option is required to indicate that the input schema (the bindings) should be used rather than the schema returned by the query.
Update
may also be used to the same effect.
Schema: applications
The input schema of our REST query
We use an options picker in the form to provide our possible status values.
Field: status
Adds the selection to the form under the name status
Options source: Custom
Custom options are specified using the Define Options
drawer
We use a data provider to run the REST query
Data: applications
The REST query
To link the query bindings to the form we use the bindings drawer
The value of the binding is {{ Status form.Fields.status }}
which represents the status field in our form.
We are now able to:
Specify a binding used in a REST query
Specify where the value of that binding will be used using handlebars
Create an application that supplies data to the binding and runs the query