Mockoon offers the following helpers which can return information relative to the entering request:
body
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
takes the following form key.0.key.5.key
and is based on the object-path library. 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.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
bodyRaw
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
takes the following form key.0.key.5.key
and is based on the object-path library. 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}}
.Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Path to the body property |
1 | string | Default value if property is not found |
Examples
Copyvalue value
queryParam
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
takes the following form key.0.key.5.key
. The syntax is based on NPM object-path package.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.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
queryParamRaw
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
takes the following form key.0.key.5.key
. The syntax is based on NPM object-path package.path
is omitted ({{queryParamRaw}}
).path
, the default value will be used.queryParam
within handlebars' helpers such as {{#each}}
and {{#if}}
.Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Path to the query param property |
1 | string | Default value if property is not found |
Examples
Copyvalue value
urlParam
Get a named parameter from the route /:paramName1/:paramName2
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Route parameter name |
Examples
Copy
cookie
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
header
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
hostname
Returns the request hostname.
Examples
Copy
ip
Returns the request IP address.
Examples
Copy
method
Returns the request method (GET, PUT, POST, etc.).
Examples
Copy
baseUrl
Returns the base URL of the request: protocol, host, port and API prefix.
Examples
Copy