Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamock HTTP server

Installation

For now, simply use cargo run to build and start the server

Define your mocks

Add a new mock

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"
}'

List currently registered mock

curl --request GET \
  --url http://localhost:3000/mocks/list

List currently received calls

curl --request GET \
  --url http://localhost:3000/calls/list

Reset the mocks

curl --request DELETE \
  --url http://localhost:3000/mocks/reset

Use the mocks

The 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/request1

Preloading

This app support preloading the mocks

  • mocks should be stored in files using the jsonlines format
  • each line have the same schema as the /add route
  • 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.jsonl

Contributing

See CONTRIBUTING.md

Testing

cargo test -p rusty-dynamock-http-server --test cucumber -- --color=never

About

A basic tool to dynamically mock any HTTP server. Powered by Rust

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages