REST Bindings Example

Using bindings in a REST query

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

An application using REST bindings to filter data

Creating a binding

We can create a binding named status with a default value of all.

Adding a binding

Using a binding

Using handlebars the binding can be referenced throughout the query in the following places:

  • URL

  • Params

  • Headers

  • Body

  • Transformer

Params example

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.

Using a binding in a param

Headers example

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.

Using a binding in a header

Body example

The binding can be used in any part of the request body. e.g. as the value of a json field.

Using a binding in the body

Supplying data to a binding

In our application we have the following structure:

Form: Status Form

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

Options Picker: Picker

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

Data Provider: Applications provider

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

Using the query bindings drawer

The value of the binding is {{ Status form.Fields.status }} which represents the status field in our form.

Conclusion

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

Last updated