Last active
May 20, 2021 13:35
-
-
Save mertyildiran/685b983751c03f56468665562f725dd8 to your computer and use it in GitHub Desktop.
Mockintosh: mocks for microservice environments - Part 3: HTTP Response Templating (Handlebars & Jinja2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
- port: 8081 | |
endpoints: | |
- path: /api-call | |
response: | |
status: "{{ request.queryString.rc }}" | |
headers: | |
content-type: '{{ request.headers.accept }}' | |
x-custom-id: '{{ random.int 0 1000 }}' | |
body: '{"result": "created", "name": "{{fake.lastname}}" }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response: | |
body: '@some/path/my_template.json.hbs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ escapeHtml '& < \" >' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
templatingEngine: Jinja2 | |
services: | |
- name: Mock for Service1 | |
hostname: service1.example.com | |
port: 8001 | |
endpoints: | |
- path: "/users" | |
method: GET | |
response: | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
useTemplating: true | |
body: "@templates/users.json.j2" | |
- path: "/users/{{ id }}" | |
method: GET | |
response: | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
useTemplating: true | |
body: "@templates/user.json.j2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": {{ id }}, | |
"firstName": "{{ fake.first_name() }}", | |
"lastName": "{{ fake.last_name() }}", | |
"friends": [{% for n in range(range(5) | random) %} | |
{ | |
"id": {{ random.int(100000, 999999) }} | |
}{% if not loop.last %},{% endif %} | |
{% endfor %}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"users": [{% for n in range(100) %} | |
{ | |
"id": {{ random.int(100000, 999999) }}, | |
"firstName": "{{ fake.first_name() }}", | |
"lastName": "{{ fake.last_name() }}", | |
"friends": [{% for n in range(range(5) | random) %} | |
{ | |
"id": {{ random.int(100000, 999999) }} | |
}{% if not loop.last %},{% endif %} | |
{% endfor %}] | |
}{% if not loop.last %},{% endif %} | |
{% endfor %}], | |
"total": 10 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment