Skip to content

Commit

Permalink
Working example for static mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
DawMatt authored and daveshanley committed Feb 24, 2025
1 parent d2a7fff commit 55d84f6
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions static-mock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To enable static mocking, you need to set the `--static-mock-dir` argument to a

Example:
```bash
wiretap --static-mock-dir /path/to/mocks
wiretap --static-mock-dir /path/to/mocks -u http://some.api-host-outhere.some-domain.com
```

When this path is set, Wiretap will expect mock definitions and response body JSON files in the following structure:
Expand Down Expand Up @@ -200,7 +200,31 @@ The `--static-mock-dir` should point to a directory that contains the following
}
```

With this configuration, when Wiretap receives a `GET` request to `/test`, it will respond with the content of `test.json`.
4. **Run wiretap**:

```bash
wiretap -u "http://localhost:8089" --static-mock-dir "/path/to/mocks" --port 80
```

Note: Any requests not matching a static mock will be proxied to the URL specified by the `-u` parameter.

5. **Make a request via curl**:

```bash
curl --location --request GET 'http://localhost/test?test=ok&arr=1&arr=2' \
--header 'Content-Type: application/json' \
--data '{
"test": "ok"
}'
```

With this configuration, when Wiretap receives a `GET` request to `/test`, it will respond with the following JSON which represents the content of `test.json` after substituting the appropriate query parameter value:

```json
{
"test": "2"
}
```

## Notes

Expand Down

0 comments on commit 55d84f6

Please sign in to comment.