Skip to main content

Dynamic Parameter

Defining Parameters

The dynamic parameter is a crucial feature that allows you to use request parameters in your SQL files, making your query results change according to your API request parameters.

You can use {{ context.params.parameter }} to get the request parameter. Here's a basic SQL syntax example:

SELECT * FROM public.users
WHERE age >= {{ context.params.age }};

With parameters set in SQL template, you can dynamically filter the results based on the age parameter provided in the querystring

curl -X GET "http://localhost:3000/api/users?age=18"

Using Parameters in URL Path

You can also use parameters in the URL path. For example, if you want to get a specific user by its ID, you can use the following SQL template:

SELECT * FROM public.users
WHERE id = {{ context.params.id }};

and define the request fields in the configuration file:

urlPath: /users/:id
request:
- fieldName: id
fieldIn: path

Now, you can send a request with the id parameter in the URL path.

curl -X GET "http://localhost:3000/api/users/1"

Using Parameters in Header

You can also use parameters in the request header with the following configuration.

urlPath: /users/:id
request:
- fieldName: id
fieldIn: header

Now, you can send a request with the id parameter in the header.

curl -X GET "http://localhost:3000/api/users" -H "id: 1"