Pass user input into a REST API call
Problem
You have user input from a UI component that needs to be used in a REST API call.
Solution
- Add the UI component on your Page or Component (e.g. an Input named
input
) - Create a new Page Function and select Make a REST API Request
- Enter the Path, Method, Headers, and Body for the request
- Use
{{ input.value }}
wherever you need the input’s current value - Save and test your function
Discussion
- Binding expressions within the double curly braces can contain any valid ES2020 expression. The expression is always evaluated client-side first and sent to the server for proxying.
- Since all requests are proxied by the backend, you do not have to consider CORS / CSP headers.
- You can configure the resource’s base path and default headers in the REST API Resource’s settings.
- Avoid putting secrets such as Authorization header tokens in headers directly. Instead, use secrets using the
${{ MY_SECRET }}
syntax.