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 external 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"}'
headersAll 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:
- endpoint:
method: POST
path: /
response:
status: 200
headers:
Content-Type: application/json
body: >
{
"header-params": "{{headers.field-name}}"
}
Sending data:
curl -X POST http://.../
-H 'Content-Type: application/json'
-H 'Field-Name: dynamic field via header'
Can you improve this documentation? These fine people already did:
Avelino & João Eduardo MedeirosEdit 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 |