Mockoon offers the following helpers which can return information relative to the entering request:
bodybodyRawqueryParamqueryParamRawqueryParamsurlParamurlParamscookieheaderheadershostnameipmethodbaseUrlGet the value at a given path from the request's body if the Content-Type is set to application/json, application/x-www-form-urlencoded, multipart/form-data, application/xml, application/soap+xml or text/xml. This helper is designed to retrieve data, stringify it, it order to use it directly in a response. To reuse the retrieved data (strings, booleans, arrays, etc.) with other helpers (each, if, etc.), use the bodyRaw helper below.
The path supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot.
XML bodies are parsed using xml-js package. Please refer to this page or the package documentation for more information on how the XML is parsed and how to fetch specific properties.
multipart/form-data supports fields and files. Uploaded files will not be stored, but their metadata (filename, mimetype, size) will be available in the request body:
Copy{ "field1": "value1", "file1": { "filename": "file1.txt", "mimetype": "text/plain", "size": 1234 } }
Full objects or arrays can be retrieved by the helper.
The full request's body can also be fetched when the path is omitted ({{body}}) independently from the request's Content-Type.
If no value is present at the requested path, the default value will be used.
A third parameter (boolean) can be set to true to returns a stringified value even if it's a primitive.
📘 Check the supported requests body formats documentation for more information on how the request body is parsed.
🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Path to the body property |
| 1 | string | Default value if property is not found |
| 2 | boolean | Stringify primitive values |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax -->
Get the raw value (string, boolean, array, etc.) at a given path from the request's body if the Content-Type is set to application/json, application/x-www-form-urlencoded, multipart/form-data, application/xml, application/soap+xml or text/xml. This "raw" helper is designed to give you access to the values to use them with other helpers (each, if, etc.). To directly use the stringified data in the response, use the body helper above.
The path supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot.
XML bodies are parsed using xml-js package. PLease refer to this page or the package documentation for more information on how the XML is parsed and how to fetch specific properties.
multipart/form-data only supports fields and files. Uploaded files will not be stored, but their metadata (filename, mimetype, size) will be available in the request body:
Copy{ "field1": "value1", "file1": { "filename": "file1.txt", "mimetype": "text/plain", "size": 1234 } }
Full objects or arrays can be retrieved by the helper.
The full request's raw body can also be fetched when the path is omitted ({{bodyRaw}}) independently from the request's Content-Type.
If no value is present at the requested path, the default value will be used.
This helper allows the use of body within handlebars' helpers such as {{#each}} and {{#if}}.
📘 Check the supported requests body formats documentation for more information on how the request body is parsed.
🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Path to the body property |
| 1 | string | Default value if property is not found |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax --> value value
Get the value at a given path from the request's query string. Complex query strings with arrays and objects are supported. This helper is designed to retrieve data to be served in a response. To reuse the retrieved data with other helpers (each, if, etc.), use the queryParamRaw helper below.
path supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot.path is omitted ({{queryParam}}). It will be stringified and can be used in a JSON body for example.path, the default value will be used.🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Path to the query param property |
| 1 | string | Default value if property is not found |
| 2 | boolean | Stringify primitive values |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax -->
Get the raw value at a given path from the request's query string. Complex query strings with arrays and objects are supported. This "raw" helper is designed to work with other helpers (each, if, etc.). To directly use the retrieved data in the response, use the queryParam helper above.
path supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot.path is omitted ({{queryParamRaw}}).path, the default value will be used.queryParam within handlebars' helpers such as {{#each}} and {{#if}}.🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Path to the query param property |
| 1 | string | Default value if property is not found |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax --> value value
Returns an object containing all query parameters from the request URL. This helper is useful for iterating over all query parameters.
Examples
Copy<!-- Iterate over all query parameters --> : <!-- Get all query parameters as JSON --> <!-- Check if a specific query parameter exists --> Page parameter provided:
Get a named parameter from the route /:paramName1/:paramName2.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Route parameter name |
Examples
Copy
Returns an object containing all URL parameters from the route. This helper is useful for iterating over all URL parameters.
Examples
Copy<!-- Iterate over all URL parameters --> : <!-- Get all URL parameters as JSON --> <!-- Check if a specific URL parameter exists --> User ID provided:
Get the content of a cookie or returns a default value if the cookie is not present.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Cookie name |
| 1 | string | Default value if cookie is not found |
Examples
Copy
Get content from any request header or returns a default value if header is not present.
| Arguments (ordered) | Type | Description |
|---|---|---|
| 0 | string | Header name |
| 1 | string | Default value if header is not found |
Examples
Copy
Returns an object containing all request headers. This helper is useful for iterating over all headers.
Examples
Copy<!-- Iterate over all headers --> : <!-- Get all headers as JSON --> <!-- Check if a specific header exists --> Authorization header provided
Returns the request hostname.
Examples
Copy
Returns the request IP address.
Examples
Copy
Returns the request method (GET, PUT, POST, etc.).
Examples
Copy
Returns the base URL of the request: protocol, host, port and API prefix.
Examples
Copy