Let's create a text-based imposter with multiple stubs. Binary imposters
cannot use the matches
predicate.
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
Content-Type: application/json
{
"port": 4550,
"protocol": "tcp",
"mode": "text",
"stubs": [
{
"responses": [{ "is": { "data": "first response" } }],
"predicates": [{
"matches": { "data": "^first\\Wsecond" },
"caseSensitive": true
}]
},
{
"responses": [{ "is": { "data": "second response" } }],
"predicates": [{ "matches": { "data": "second\\s+request" } }]
},
{
"responses": [{ "is": { "data": "third response" } }],
"predicates": [{ "matches": { "data": "second\\s+request" } }]
}
]
}
The first stub requires a case-sensitive match on a string starting with "first", followed by a non-word character, followed by "second":
echo 'first second' | nc localhost 4550
first response
The second stub is not case-sensitive.
echo 'Second Request' | nc localhost 4550
second response
The third stub will never run, since it matches the same requests as the
second stub. mountebank always chooses the first stub that matches based on
the order you add them to the stubs
array when creating the
imposter.
DELETE /imposters/4550 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json