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.bodyendpoint.response.external-body.path understand what extended body is herepath-paramsParameter 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:
- endpoint:
method: GET
path: /:field-name
response:
status: 200
headers:
Content-Type: application/json
body: >
{
"path-params": "{{path-params.field-name}}"
}
query-paramsParameter 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:
- endpoint:
method: GET
path: /
response:
status: 200
headers:
Content-Type: application/json
body: >
{
"path-params": "{{query-params.field-name}}"
}
json-paramsParameter 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:
- endpoint:
method: POST
path: /
response:
status: 200
headers:
Content-Type: application/json
body: >
{
"json-params": "{{json-params.field-name}}"
}
Sending data:
curl -X POST http://.../
-H 'Content-Type: application/json'
-d '{"field-name":"dynamic field name"}'
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |