Skip to content

Commit

Permalink
Prepare new release
Browse files Browse the repository at this point in the history
Add environment variables documentation see mockoon/mockoon#849
Add new docs variables pages
Update docs images
  • Loading branch information
255kb committed Feb 29, 2024
1 parent cd2b772 commit 50feea8
Show file tree
Hide file tree
Showing 244 changed files with 3,883 additions and 158 deletions.
4 changes: 2 additions & 2 deletions components/plans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const pricing = {
},
templatesQuota: 200,
discount: '🏷️ 2 months free',
maxSeats: 20
maxSeats: 10
},
ENTERPRISE: {
MONTHLY: {
Expand Down Expand Up @@ -530,7 +530,7 @@ const Plans: FunctionComponent<{ showFree: boolean; showTagline: boolean }> =
<i className='icon-check'></i>
</div>

<p>Organizations up to 20 seats</p>
<p>Organizations up to 10 seats</p>
</div>
<div className='py-4 mt-auto'>
<span className='badge rounded-pill bg-gray-300 text-gray-800'>
Expand Down
4 changes: 2 additions & 2 deletions content/blog/december-2023-news.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We have released three new versions since September:

- **[October's v5.1.0](/releases/5.1.0/)** with a new command palette (see below), Faker.js v8 migration, and support for [Range headers](/docs/latest/response-configuration/file-serving/#serving-a-range-of-bytes-from-a-file).
- **[November's v6.0.0](/releases/6.0.0/)** with the [callbacks](/docs/latest/callbacks/overview/) feature and new [CLI import/export commands](https://github.com/mockoon/mockoon/tree/main/packages/cli#import-command).
- **[December's v6.1.0](/releases/6.1.0/)** with [CRUD filtering and searching](/docs/latest/api-endpoints/crud-routes/#filtering-sorting-and-pagination-on-the-main-get-route) and [global variables](/docs/latest/global-variables/overview/).
- **[December's v6.1.0](/releases/6.1.0/)** with [CRUD filtering and searching](/docs/latest/api-endpoints/crud-routes/#filtering-sorting-and-pagination-on-the-main-get-route) and [global variables](/docs/latest/variables/global-variables/).

## ☎️ Callbacks

Expand Down Expand Up @@ -62,7 +62,7 @@ Mockoon now supports **global variables** that can be set and accessed using the

These variables can be used anywhere templating is supported, like the response body or headers. Their values are reset when the environment is stopped or restarted.

📘&nbsp;[Read the documentation](/docs/latest/global-variables/overview/)
📘&nbsp;[Read the documentation](/docs/latest/variables/global-variables/)

## 🎨 Command palette

Expand Down
2 changes: 1 addition & 1 deletion content/docs/latest/callbacks/using-callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ After [creating callbacks](docs:callbacks/overview), you can link them in your r

To link a callback to a route response, choose "Callbacks" in the route response menu:

![click on the callbacks tab in the route response menu{997x153}](docs-img:open-route-response-callbacks.png)
![click on the callbacks tab in the route response menu{1004x174}](docs-img:open-route-response-callbacks.png)

Then, click on the "plus" button to add a new callback, and select the callback you want to link:

Expand Down
8 changes: 4 additions & 4 deletions content/docs/latest/response-configuration/response-body.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Each [route response](docs:route-responses/multiple-responses) can serve a diffe

You can choose each option using the body selector:

![body type toggle buttons{1264x540}](docs-img:body-type-toggle.png)
![body type toggle buttons{1264x547}](docs-img:body-type-toggle.png)

## Body editor (inline)

You can use the body editor to directly create your response content. It supports all the [templating helpers](docs:templating/overview).

![inline body editor{1169x807}](docs-img:inline-body-editor.png)
![inline body editor{1169x800}](docs-img:inline-body-editor.png)

> Mockoon will save the content of the inline body editor directly in your [data file](docs:mockoon-data-files/data-storage-location).
> Using an external file could improve the performance for large content.
Expand All @@ -29,14 +29,14 @@ You can use the body editor to directly create your response content. It support

You can also choose to serve an external file, using the second option:

![external file linking input{1169x807}](docs-img:body-file-serving.png)
![external file linking input{1169x800}](docs-img:body-file-serving.png)

Please refer to the [file serving documentation](docs:response-configuration/file-serving) for more information.

## Data bucket

You can finally choose to serve the content of a data bucket using the third option:

![data bucket linking select menu{1169x807}](docs-img:body-data-bucket.png)
![data bucket linking select menu{1169x800}](docs-img:body-data-bucket.png)

Please refer to the [data bucket documentation](docs:data-buckets/overview) for more information.
2 changes: 1 addition & 1 deletion content/docs/latest/route-responses/dynamic-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Depending on the **target**, the way to access properties may be different:
- **headers**: a header name like `Accept` or `Content-Type`.
- **cookies**: the cookie name like `Session-id`.
- **route param**: a route param name without the colon (":"), `:userId` becoming `userId`.
- **global variable**: a [global variable](docs:global-variables/overview) name like `myVar`. You can use a path to access one of its properties if the variable is storing arrays or objects. Two syntaxes are supported, [object-path](https://www.npmjs.com/package/object-path) or [JSONPath Plus](https://www.npmjs.com/package/jsonpath-plus). When using object-path, properties containing dots are supported by escaping the dots: `key.key\.with\.dot`. Examples: `myVar.property.subProperty`, `myVar.property.0.subProperty` or `$.myVar.property`.
- **global variable**: a [global variable](docs:variables/global-variables) name like `myVar`. You can use a path to access one of its properties if the variable is storing arrays or objects. Two syntaxes are supported, [object-path](https://www.npmjs.com/package/object-path) or [JSONPath Plus](https://www.npmjs.com/package/jsonpath-plus). When using object-path, properties containing dots are supported by escaping the dots: `key.key\.with\.dot`. Examples: `myVar.property.subProperty`, `myVar.property.0.subProperty` or `$.myVar.property`.
- **request number**: _nothing has to be provided here for the request number_.

For **body** and **query string**, if the property is an array, Mockoon will automatically check in the array if at least one item matches the value.
Expand Down
127 changes: 9 additions & 118 deletions content/docs/latest/templating/mockoon-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ In addition to Handlebars' built-in helpers, Mockoon offers the following helper
| [`len`](#len) | |
| [`filter`](#filter) | |

| Math | | Variables |
| ----------------------- | --------------------- | ------------------------------- |
| [`add`](#add) | [`eq`](#eq) | [`setVar`](#setvar) |
| [`subtract`](#subtract) | [`gt`](#gt) | [`getVar`](#getvar) |
| [`multiply`](#multiply) | [`gte`](#gte) | [`setGlobalVar`](#setglobalvar) |
| [`divide`](#divide) | [`lt`](#lt) | [`getGlobalVar`](#getglobalvar) |
| [`modulo`](#modulo) | [`lte`](#lte) | |
| [`ceil`](#ceil) | [`toFixed`](#tofixed) | |
| [`floor`](#floor) | [`round`](#round) | |
| Math | |
| ----------------------- | --------------------- |
| [`add`](#add) | [`eq`](#eq) |
| [`subtract`](#subtract) | [`gt`](#gt) |
| [`multiply`](#multiply) | [`gte`](#gte) |
| [`divide`](#divide) | [`lt`](#lt) |
| [`modulo`](#modulo) | [`lte`](#lte) |
| [`ceil`](#ceil) | [`toFixed`](#tofixed) |
| [`floor`](#floor) | [`round`](#round) |

| Strings | | Dates | Misc |
| ------------------------- | ----------------------- | --------------------------------- | ------------------------------- |
Expand Down Expand Up @@ -705,115 +705,6 @@ Create a valid ObjectId. It can generates the ObjectId based on the specified ti
{{objectId '54495ad94c934721ede76d90'}}
```

## setVar

Set a variable to be used later in the template. The value can be the result of another helper. To use it elsewhere in the template, refer to the variable with its name prefixed with an `@`: `{{@varname}}`. The variable can also be used as a helper parameter: `{{#repeat @varname}}...{{/repeat}}`.
Variables declared in a block helper will be scoped to the block and unavailable outside.

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------- |
| 0 | string | Variable name |
| 1 | any | Variable value |

**Examples**

```handlebars
{{setVar 'varname' 'value'}}
{{setVar 'varname' (body 'id')}}
usage:
{{@varname}}
{{#repeat @varname}}...{{/repeat}}
declare a variable in a block helper:
{{#repeat 5}}
{{setVar 'random' (oneOf (array '1' '2' '3'))}}
{{@random}}
{{/repeat}}
{{setVar 'myArray' (array '1' '2' '3')}}
{{#each @myArray}}
{{setVar 'eachIndex' @index}}
{{@eachIndex}}
{{/repeat}}
```

## getVar

Dynamically get a variable set with [`setVar`](#setvar).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | ------------- |
| 0 | string | Variable name |

**Examples**

```handlebars
{{setVar 'varname' 'value'}}
{{getVar 'varname'}}
{{getVar (concat 'var' 'name')}}
{{getVar (body 'property')}}
```

## setGlobalVar

Set a global variable to be used anywhere templating is supported (body, headers, etc.). Global variables are available on all the routes of an environment and they are reset when the environment is restarted.

- The variable name and values can be dynamically created using other helpers.
- The variable can store any kind of data (arrays, objects, string, etc.).
- To get the value of a global variable, use the [`{{getGlobalVar 'varName'}}` helper below](#getglobalvar).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------- |
| 0 | string | Variable name |
| 1 | any | Variable value |

**Examples**

```handlebars
{{setGlobalVar 'varName' 'value'}}
{{setGlobalVar 'varName' (bodyRaw 'id')}}
{{setGlobalVar (queryParam 'param1') (bodyRaw 'id')}}
```

## getGlobalVar

Get a global variable's value set with [`setGlobalVar`](#setglobalvar). Global variables are available on all the routes of an environment and they are reset when the environment is restarted.

- The variable name and path can be dynamically created using other helpers.
- The `path` supports two syntaxes, [object-path](https://www.npmjs.com/package/object-path) or [JSONPath Plus](https://www.npmjs.com/package/jsonpath-plus). When using object-path, properties containing dots are supported by escaping the dots: `key.key\.with\.dot`.
Please note that a value can be retrieved at the path if the variable contains valid JSON.
- Primitives and data structures can be retrieved by the helper and reused in other helpers (see example below).
- The full variable content (array, object, etc.) can be fetched when the `path` is omitted (`{{getGlobalVar 'varname'}}`).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------------------- |
| 0 | string | Variable name |
| 1 | string | Path to the value property |

**Examples**

```handlebars
{{getGlobalVar 'varname'}}
{{getGlobalVar (bodyRaw 'property')}}
{{getGlobalVar (urlParam 'id')}}
<!-- Using object-path syntax -->
{{getGlobalVar 'varName' 'path.to.property'}}
{{getGlobalVar 'varName' 'deep.property\.with\.dot'}}
<!-- using JSONPath syntax -->
{{getGlobalVar 'varName' '$.array.[*].property'}}
{{#repeat (getGlobalVar 'varname')}}...{{/repeat}}
{{#each (getGlobalVar 'varName')}}...{{/each}}
<!-- Stringify the variable content -->
{{{stringify (getGlobalVar 'varName')}}}
```

## includes

Search whether a string can be found in another string and returns the appropriate boolean.
Expand Down
2 changes: 1 addition & 1 deletion content/docs/latest/templating/mockoon-response-helpers.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Response helpers
meta:
title: Dynamically customize the response with with templating helpers
title: Dynamically customize your response with templating helpers
description: "Dynamically customize your mock environments response with Mockoon's templating response helpers. All formats are supported: JSON, CSV, HTML, etc."
order: 503
---
Expand Down
149 changes: 149 additions & 0 deletions content/docs/latest/templating/mockoon-variables-helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
title: Variables helpers
meta:
title: Dynamically customize your responses with variables templating helpers
description: "Dynamically customize your mock environments response with Mockoon's templating variables helpers. All formats are supported: JSON, CSV, HTML, etc."
order: 503
---

# Templating variables helpers

---

Mockoon offers the following helpers which can help you set **local or global variables**, and **access environment variables** in your templates:

- [`setVar`](#setvar)
- [`getVar`](#getvar)
- [`setGlobalVar`](#setglobalvar)
- [`getGlobalVar`](#getglobalvar)
- [`getEnvVar`](#getenvvar)

## setVar

Set a variable to be used later in the template. The value can be the result of another helper. To use it elsewhere in the template, refer to the variable with its name prefixed with an `@`: `{{@varname}}`. The variable can also be used as a helper parameter: `{{#repeat @varname}}...{{/repeat}}`.
Variables declared in a block helper will be scoped to the block and unavailable outside.

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------- |
| 0 | string | Variable name |
| 1 | any | Variable value |

**Examples**

```handlebars
{{setVar 'varname' 'value'}}
{{setVar 'varname' (body 'id')}}
usage:
{{@varname}}
{{#repeat @varname}}...{{/repeat}}
declare a variable in a block helper:
{{#repeat 5}}
{{setVar 'random' (oneOf (array '1' '2' '3'))}}
{{@random}}
{{/repeat}}
{{setVar 'myArray' (array '1' '2' '3')}}
{{#each @myArray}}
{{setVar 'eachIndex' @index}}
{{@eachIndex}}
{{/repeat}}
```

## getVar

Dynamically get a variable set with [`setVar`](#setvar).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | ------------- |
| 0 | string | Variable name |

**Examples**

```handlebars
{{setVar 'varname' 'value'}}
{{getVar 'varname'}}
{{getVar (concat 'var' 'name')}}
{{getVar (body 'property')}}
```

## setGlobalVar

Set a global variable to be used anywhere templating is supported (body, headers, etc.). Global variables are available on all the routes of an environment and they are reset when the environment is restarted.

- The variable name and values can be dynamically created using other helpers.
- The variable can store any kind of data (arrays, objects, string, etc.).
- To get the value of a global variable, use the [`{{getGlobalVar 'varName'}}` helper below](#getglobalvar).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------- |
| 0 | string | Variable name |
| 1 | any | Variable value |

**Examples**

```handlebars
{{setGlobalVar 'varName' 'value'}}
{{setGlobalVar 'varName' (bodyRaw 'id')}}
{{setGlobalVar (queryParam 'param1') (bodyRaw 'id')}}
```

## getGlobalVar

Get a global variable's value set with [`setGlobalVar`](#setglobalvar). Global variables are available on all the routes of an environment and they are reset when the environment is restarted.

- The variable name and path can be dynamically created using other helpers.
- The `path` supports two syntaxes, [object-path](https://www.npmjs.com/package/object-path) or [JSONPath Plus](https://www.npmjs.com/package/jsonpath-plus). When using object-path, properties containing dots are supported by escaping the dots: `key.key\.with\.dot`.
Please note that a value can be retrieved at the path if the variable contains valid JSON.
- Primitives and data structures can be retrieved by the helper and reused in other helpers (see example below).
- The full variable content (array, object, etc.) can be fetched when the `path` is omitted (`{{getGlobalVar 'varname'}}`).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | -------------------------- |
| 0 | string | Variable name |
| 1 | string | Path to the value property |

**Examples**

```handlebars
{{getGlobalVar 'varname'}}
{{getGlobalVar (bodyRaw 'property')}}
{{getGlobalVar (urlParam 'id')}}
<!-- Using object-path syntax -->
{{getGlobalVar 'varName' 'path.to.property'}}
{{getGlobalVar 'varName' 'deep.property\.with\.dot'}}
<!-- using JSONPath syntax -->
{{getGlobalVar 'varName' '$.array.[*].property'}}
{{#repeat (getGlobalVar 'varname')}}...{{/repeat}}
{{#each (getGlobalVar 'varName')}}...{{/each}}
<!-- Stringify the variable content -->
{{{stringify (getGlobalVar 'varName')}}}
```

## getEnvVar

Get an environment variable. If the environment variable is not set, the default value will be used.

By default, only environment variables with the `MOCKOON_` prefix are available. Learn more in the [environment variables documentation](docs:variables/environment-variables).

| Arguments (ordered) | Type | Description |
| ------------------- | ------ | ------------------------- |
| 0 | string | Environment variable name |
| 1 | any | Default value |

**Examples**

```handlebars
{{setVar 'varname' 'value'}}
{{getEnvVar 'VARIABLE_NAME' 'default value'}}
{{getEnvVar 'VARIABLE_NAME'}}
{{getEnvVar (body 'property')}}
```

0 comments on commit 50feea8

Please sign in to comment.