For now, simply use cargo run to build and start the server
With a query string
curl --request PUT \
--url http://localhost:3000/mocks/add \
--header 'Content-Type: application/json' \
--data '{
"request": {
"method": "GET",
"path": "/request1",
"headers": {
"some-header": "any-value"
},
"query": {
"some-key": "any-value"
}
},
"response": {
"body": {"some": "content"},
"status_code": 201
}
}'Query the mock
curl --request GET \
--url 'http://localhost:3001/request1?some-key=any-value' \
--header 'some-header: any-value'With an HTTP body
curl --request PUT \
--url http://localhost:3000/mocks/add \
--header 'Content-Type: application/json' \
--data '{
"request": {
"method": "POST",
"path": "/request2",
"body": {
"json": {"some": "data"}
}
},
"response": {
"body": {"some": "content"},
"status_code": 201
}
}'Query the mock
curl --request POST \
--url http://localhost:3001/request2 \
--header 'Content-Type: application/json' \
--data '{
"some": "data"
}'With response that vary over calls
curl --request PUT \
--url http://localhost:3000/mocks/add \
--header 'Content-Type: application/json' \
--data '{
"request": {
"method": "GET",
"path": "/request3"
},
"usage_count": 1,
"response": {
"body": {"some": "content"},
"status_code": 200
}
}'
curl --request PUT \
--url http://localhost:3000/mocks/add \
--header 'Content-Type: application/json' \
--data '{
"request": {
"method": "GET",
"path": "/request3"
},
"usage_count": 1,
"response": {
"body": {"some": "content2"},
"status_code": 200
}
}'Query the mock
curl --request GET \
--url http://localhost:3001/request3 \
--header 'Content-Type: application/json' \
--data '{
"some": "data"
}'
curl --request GET \
--url http://localhost:3001/request3 \
--header 'Content-Type: application/json' \
--data '{
"some": "data"
}'curl --request GET \
--url http://localhost:3000/mocks/listcurl --request GET \
--url http://localhost:3000/calls/listcurl --request DELETE \
--url http://localhost:3000/mocks/resetThe entrypoint use another port 3001 to respond on any request according to registered mocks.
An unknown request respond with a 404 status code.
curl --request GET \
--url http://localhost:3001/request1This app support preloading the mocks
- mocks should be stored in files using the jsonlines format
- each line have the same schema as the
/addroute - pass filepath as input arguments
echo '{"request":{"method":"GET","path":"/status"},"response":{"body":"OK","status_code":200}}' > /tmp/test-input-file.jsonl
cargo run -- /tmp/test-input-file.jsonlSee CONTRIBUTING.md
cargo test -p rusty-dynamock-http-server --test cucumber -- --color=never