Embedded Blocks

You can create your own variables with code blocks that can be embedded in the main body of the response. You can also generate arrays of data using loops.

Your first block

Let's create a list of user's credit cards using inline blocks. First, let's fill Body with the main data structure:

{
  "message": null,
  "response": {$creditCards}
}

The creditCards variable does not currently exist. Let's create the first block and call it creditCards.

The block consists of the following components:

  • Text field for the value. The functionality of the field is identical to the main field for the response body and supports variables. Important note - if the number of iterations is greater than 1, then the text value must be valid JSON.

  • Iterations - the number of JSON objects in the array. As stated earlier, plain text does not support more than 1 iteration.

  • Variable name is a unique name that you will use in the main body of the response. Check that the variable name does not conflict with standard variables.

That's it, the credit Cards variable has been created! The response will contain 2 credit cards with unique numbers and ID. Of course, you can use variables without loops (set 1 iteration) and variables with random data to keep your code clean.

Use the embeddedLoopIndex variable to get the iteration index. This can be useful when constructing arrays of objects with integer IDs

Below is the result of a request to our endpoint. With each request, we will receive different card numbers but the same IDs, because we use a special variable for blocks. This way you can create dynamic responses of any structure.

{
  "message": null,
  "response": [
    {
      "id": "1",
      "number": "4716286293011773"
    },
    {
      "id": "2",
      "number": "6011968455696049"
    }
  ]
}

Search and render cache

Response body created using inline blocks supports search based on URI parameters.

As mentioned earlier, with each request we generate new data if we use variables. If we want to search our body, the right thing to do is to “freeze” the response. For this you should use Render cache.

Last updated

#20:

Change request updated