A simple and lightweight tool to create and share mocked services for development or test environment.
Mocker could be used through the command line or docker container.
$ go get github.com/maykonlf/mocker/cmd/mocker
-addr
: mocker server API address (default ":8081")-f
: mock service spec file path (default "./mocker.yaml")
Go to a path containing the mocker.yaml
spec file and run the following command on your terminal:
$ mocker
Then you can make requests to your mocked service and it will respond as configured on your mocker.yaml
file.
$ docker run -d -v .:/mocker -p 8081:8081 maykonlf/mocker
api
: describes mocked API specsroutes
: list of matching API routes.methods
: list of matching HTTP methods (must be in lowercase)response
: describes the response mocker should return when the received requests match the specs above.status
: HTTP response status codeheaders
: key-value response headersbody
: response body stringtime
: time to wait before responding to the request - useful to simulate API processing time (ex:200ms
,1s
)
# mocker.yaml
api:
- routes:
- /v1/books
- /v2/books
methods:
- get
response:
status: 200
headers:
Content-Type: application/json
body: >
[{
"id: "7d619e9b-9fd2-4abb-b9b4-cfa5811e97a5",
"title": "Clean Code: A Handbook of Agile Software Craftsmanship"
}, {
"id: "46c1bc9f-2ae0-4d73-bf9d-531fa1898537",
"title": "Clean Architecture: A Craftsman's Guide to Software Structure and Design"
}, {
"id: "c8daf68a-5a28-4438-91c1-9f5835ad6439",
"title": "Refactoring: Improving the Design of Existing Code"
}]
time: 200ms