Skip to content

Commit

Permalink
Merge pull request #27 from daanoz/feature/fix-nested-wildcard-matches
Browse files Browse the repository at this point in the history
Update readme.MD after changed wildcard support
  • Loading branch information
muratcorlu committed Sep 27, 2018
2 parents c8d0ac4 + 17aa4d1 commit ac7e8de
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ module.exports = function (request, response) {
response.statusCode = 403;
response.end();
} else {
var filePath = path.join(__dirname, 'POST.json');
var filePath = path.join(__dirname, 'POST.json');
var stat = fs.statSync(filePath);

response.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': stat.size
Expand Down Expand Up @@ -318,7 +318,7 @@ module.exports = function (request, response) {
}
```

## Wildcards in paths
## Wildcards in requests

You can use wildcards for paths to handle multiple urls(like for IDs). If you create a folder structure like `api/users/__user_id__/GET.js`, all requests like `/api/users/321` or `/api/users/1` will be responded by custom middleware that defined in your `GET.js`. Also id part of the path will be passed as a request parameter named as `user_id` to your middleware. So you can write a middleware like that:

Expand All @@ -332,6 +332,19 @@ module.exports = function (request, response) {
}
```

You can also define `ANY.js` or `ANY.json` files that catch all methods.

`api/users/__user_id__/ANY.js` file:

```js
module.exports = function (request, response) {
response.json({
id: request.params.user_id,
method: request.method
});
}
```

## XML Support

Api Mocker also can handle XML responses. As you can see, for custom responses, it's not an issue. Because you are completely free about responses in custom responses. But for simple mocks, api mocker try to find a json file by default. You can set that behaviour as `type` in api mocker configuration:
Expand Down

0 comments on commit ac7e8de

Please sign in to comment.