Skip to content


Repository files navigation

http mock server

Build Status codecov

Returns http responses by matching requests.

Request matching defined by: host method path (its can be any - *)

Responses defined by: message body status_code headers

term mock is request matching + responses

Mock created via http POST request to /mocker_api/mocks/ (examples below)

At the same time can be created several "similar" mocks (equivalent request matching and equals responses) if no one is exclusive

When creates "overlap" mocks (equivalent request matching but different responses) then server returns http 409 status code

About mock:

  • has timeout (ttl)
  • has response type
    • single (default): A -> A A A,
    • sequence: [A, B, C] -> A B C C C ...
    • cycle: [A, B, C] -> A B C A B C ...
  • can be exclusive (no other similar mocks might be created, False by default)

Mock deleted via http DELETE request to /mocker_api/mocks/<pk>/ (response has json with key is_expired)

Mocks CRUD also available via browser (Django REST framework builtin UI)


  • create mocks:
curl -H "Content-Type: application/json" -X POST -d '{"method":"GET","route":"/42","responses":42, "is_exclusive": true}' srv:8080/mocker_api/mocks/
curl -H "Content-Type: application/json" -X POST -d '{"name":"all_match_cycle","host":"*","method":"*","route":"*","ttl":600,"responses":[{"body": "qwerty", "return_code": 201}, 42, {"body": "hello world", "headers":{"Content-Type": "application/json"}}], "response_type": "cycle"}' srv:8080/mocker_api/mocks/
{"url":"http://srv:8080/mocker_api/mocks/3/", "name":"all_match_cycle", ...
  • responses:
curl -i -X POST srv:8080/some_path
HTTP/1.1 201 Created
Content-Type: text/html; charset=utf-8

curl -i -X GET srv:8080/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

curl -i -X PUT srv:8080/some_other_path
HTTP/1.1 200 OK
Content-Type: application/json

hello world
  • show mocks:
curl -X GET srv:8080/mocker_api/mocks/
  • delete mock:
curl -X DELETE srv:8080/mocker_api/mocks/2/
curl -X DELETE srv:8080/mocker_api/mocks/3/

also available bulk creation of mocks:

curl -H "Content-Type: application/json" -X POST -d '[{"method":"GET","route":"/42","responses":42, "is_exclusive": true}, {"method":"GET","route":"/42_2","responses":42, "is_exclusive": true}]' srv:8080/mocker_api/mocks/

other examples in tests


for example via docker-compose:

docker-compose -f docker-compose.yml -f docker-compose.stage.yml up -d
docker-compose -f docker-compose.yml -f docker-compose.stage.yml run --rm --no-deps --entrypoint "" srv pytest

or any other way


http mock server, matching by: (host | '*') & (method | '*') & (path | '*'), responses: content, status_code, headers






No releases published


No packages published