Predicates in Mountebank
Predicates in Mountebank imposter files is a pretty powerful way to configure stubs. It helps us to return different responses based on the request parameters like type, query string , headers, body etc. Let us have some quick look at extracting values from request
Based on Query String
Below is an example of extracting the records based on query string.
If the request is like path?customerId=123&customerId=456&email=abc.com
Note: This is slightly modified version of code in mbtest.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
Based on Header Content
If input data is shared through values in header, that can be extracted. Below snippet is directly from mbtest.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|