Using rendering templates
how the template works within the moclojer specification file
moclojer provides a template processor to make the endpoint’s return dynamic, making it easy for you to pass parameters by URI and query string into the endpoint’s response.
We use the Selmer template engine (is inspired by the Django template engine), making it possible to place conditions and rules within the template. The Selmer documentation shows examples of how to do this.
it is possible to use template rendering in:
endpoint.response.body
endpoint.response.external-body.path
understand what external body is here
Path params path-params
path-params
Parameter passed by the endpoint’s URI/URL.
We use the :field-name
signature to pass the dynamic parameter to the URL/URI. To access this field in the template, simply use the following syntax: {{path-params.field-name}}
.
Sample:
Query params query-params
query-params
Parameter passed query string.
We use the ?field-name=dynamic field name
signature to pass the dynamic parameter to the query string, generally used in the http verb GET
. To access this field in the template, simply use the following syntax: {{query-params.field-name}}
.
Sample:
JSON params json-params
json-params
Parameter passed via JSON, generally used in the http verbs POST
, PUT
and DELETE
. To access this field in the template, simply use the following syntax: {{json-params.field-name}}
.
Sample:
Sending data:
HTTP header request headers
headers
All parameters received in the request header are passed as template variables, making it possible to use the header data to create logic (verification) and/or put it in the return (in the body). To access this field in the template, simply use the following syntax: {{headers.field-name}}
.
Sample:
Sending data:
Last updated