Return stubbed HTTP responses defined in a config file
Add the routes and the responses that you want in the config file.
A basic route definition would look like:
routes:
- path: /foo
status: 200
response: >-
{
"id": 123,
"message": "foo"
}
If the response has URL parameters then these need to be defined as follows:
routes:
- path: /foo
queries:
- show_deleted # this is the param key
- true # this is the param value
status: 200
respose: >-
{
"id": 987,
"message": "bar"
}
The reason for having them defined in a list rather than as a key/value pair is due to how the (Queries](https://www.gorillatoolkit.org/pkg/mux#Route.Queries) method is defined in the router package used (gorilla mux).
If you want the response to include a header then you can add it as such:
routes:
- path: /foo
status: 200
headers:
X-Custom: Header
X-Request-Id: ef835eaf-a658-458b-86ae-d2d771f5e745
respose: >-
{
"id": 987,
"message": "bar"
}
The artifact is stored as a docker image and is located on Docker Hub
You can also build locally if required by running make image
.
Run the docker container using make run_image
in this directory.
$ make run_image
# Running Docker Image Locally...
2019/02/14 17:33:37 starting server on :8080
Or you can run the following docker run command anywhere:
docker run --rm -v "$PWD/config.yaml:/bin/config.yaml" -p 8080:8080 davyj0nes/stubby
If you would like to contribute to this project then please check out the guidance within: CONTRIBUTING.md