Let's create an HTTP imposter with multiple stubs:
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
Content-Type: application/json
{
"port": 4556,
"protocol": "http",
"stubs": [
{
"responses": [{ "is": { "body": "first" } }],
"predicates": [{
"deepEquals": {
"query": {}
}
}]
},
{
"responses": [{ "is": { "body": "second" } }],
"predicates": [{
"deepEquals": {
"query": {
"first": "1"
}
}
}]
},
{
"responses": [{ "is": { "body": "third" } }],
"predicates": [{
"deepEquals": {
"query": {
"first": "1",
"second": "2"
}
}
}]
}
]
}
The first predicate matches only a request without a querystring.
GET /test HTTP/1.1
Host: localhost:4556
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
first
The second stub matches only if the exact querystring is sent.
GET /test?First=1 HTTP/1.1
Host: localhost:4556
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
second
The third stub matches only if both query keys are sent.
GET /test?Second=2&First=1 HTTP/1.1
Host: localhost:4556
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
third
Any additional query parameters will trigger the default HTTP response.
GET /test?Second=2&First=1&Third=3 HTTP/1.1
Host: localhost:4556
HTTP/1.1 200 OK
Connection: close
Date: Thu, 09 Jan 2014 02:30:31 GMT
Transfer-Encoding: chunked
DELETE /imposters/4556 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json