Mockoon offers the following helpers which can return information relative to the entering request:
Get the value at a given path
from the request body if the entering 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 to be served in a response. To reuse the retrieved data with other helpers (each
, if
, etc.), use the bodyRaw
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
.multipart/form-data
only supports fields. Uploaded files will be ignored.path
is omitted ({{body}}
) independently from the request's Content-Type
.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 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 at a given path
from the request body if the entering 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 work with other helpers (each
, if
, etc.). To directly use the retrieved data in the response, use the body
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
.multipart/form-data
only supports fields. Uploaded files will be ignored.path
is omitted ({{bodyRaw}}
) independently from the request's Content-Type
.path
, the default value will be used.body
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 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
Get a named parameter from the route /:paramName1/:paramName2
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Route parameter name |
Examples
Copy
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 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