The exists predicate is primarily for object data types, like
HTTP headers and query parameters. It works on string fields by simply returning
true if the exists value is true and the
string if non-empty. Setting the exists value to false
inverts the meaning.
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
Content-Type: application/json
{
"port": 4551,
"protocol": "http",
"stubs": [
{
"responses": [{ "is": { "body": "first response" } }],
"predicates": [
{
"exists": {
"query": {
"q": true,
"search": false
},
"headers": {
"Accept": true,
"X-Rate-Limit": false
}
}
}
]
},
{
"responses": [{ "is": { "body": "second response" } }],
"predicates": [
{
"exists": {
"method": true,
"body": false
}
}
]
},
{
"responses": [{ "is": { "body": "third response" } }],
"predicates": [
{
"exists": { "body": true }
}
]
}
]
}
The first stub matches if the querystring includes q, but not if it
includes search, and if the headers include Accept,
but not if they include X-Rate-Limit.
GET /?q=mountebank HTTP/1.1
Host: localhost:4551
Accept: text/plain
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
first response
The second stub matches if the request method is a
non-empty string (always true), and if the body
is empty.
GET / HTTP/1.1
Host: localhost:4551
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
second response
The last stub matches if the body is non-empty:
POST / HTTP/1.1
Host: localhost:4551
non-empty body
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
third response
DELETE /imposters/4551 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json