Response Templating

Overview

More often than not, API simulations require HTTP responses to change between requests for the same simlet. Response templating is the solution for building dynamic HTTP responses.

Simula Template Engine

definition

Simula is the API Simulator’s text template engine.

The template engine takes a template and combines it with data to produce the HTTP response.

A template consists of fragments. Some fragments don’t change and others can produce variable content.

Placeholders are a type of fragments that can produce variable content. A placeholder gets resolved to an actual value as part of rendering the template. ${ and } enclose placeholders.

Another kind of fragments that can produce variable content is the scripting fragments, or scriptlets. Scriptlets are code. The template engine executes the code upon rendering the template, which may produce output. Scriptlets are delimited by <% and %>.

The ability to change the default delimiters for placeholders and scriptlets will be removed in a future release.

Here is how to define that a response is rendered from a Simula template:

response:
  from: template
  template: Simula
  ...

The same HTTP configuration elements described in Response Stubbing can be configured with a Simula template:

  • Response Status

  • HTTP Protocol Version

  • Header Fields

  • Body, with

    • Text Body Content, or

    • Binary Body Content, with

      • Base64-Encoded Body Content, or

      • Binary Body Content From a File

  • Callback

It is just that they can be dynamic, as needed.

The next pages will cover the various aspects of configuring a template.


We would love to hear your feedback! Shoot us an email to [feedback at APISimulator.com] about anything that is on your mind.

Happy API Simulating!