Using the setting config.customResponses
in $CUSTOM_DIRECTORY/src/sdk/config/custom.sdk.config.js
, an array of responses can be defined:
config.customResponses = [
{
url: '/some/path',
response: {
...
}
},
{
url: '/another/path',
response: {
...
}
}
];
At runtime, when a request is sent by JavaScript, the mock is determined by checking whether the actual request's URL ends with one of the configured URLs within customResponses
ignoring the HTTP method. It is not necessary to fully qualify the full URL in the configuration. The first entry that matches will be used to mock the response.
In addition to matching the URL, you can optionally also provide the HTTP method:
config.customResponses = [
{
url: '/some/path',
method: 'POST', // Optional. If undefined, all HTTP methods match.
response: {
...
}
},
{
url: '/some/path',
response: {
...
}
},
];
In this example, a request sent to /some/path only matches the first mock response if the HTTP method is POST. If any other HTTP method is used for /some/path, the second mock would apply.