Skip to content

NdoleStudio/httpmock

Repository files navigation

httpmock

Build GitHub contributors GitHub license Codecov Better Stack Badge Docker Pulls

This is a mock http server which can be used to test HTTP requests and responses when building an HTTP client. You can also use it to mock a backend API in your frontend app e.g in in situations where you're still waiting for the backend API to be ready.

Server

You can use the mock server for free at httpmock.dev. The server will return the data which you specify using custom http request headers. The server will use these headers to generate the response to your http request.

  • response-body: This can any string which will be returned as the response body by the server
  • response-headers: This should be a JSON array of headers that will be returned by the server for the request
  • response-status: This is the HTTP status code of the response e.g 500, 200, 404
  • response-delay: This is the time in milliseconds that the server will wait before returning the response e.g 1000 for 1 second. The max delay you can set is 10 seconds. If you provide a larger delay, it will capped at 10 seconds.
curl -X GET https://httpmock.dev/server \
  -H 'response-body: {"id": 12334, "name": "e.g John Doe"}' \
  -H 'response-headers: [{"Content-Type":"application/json"}]' \
  -H 'response-status: 200'

or this is an example with javascript

fetch("https://httpmock.dev/server", {
    headers: {
        "response-body": '{"id": 12334, "name": "John Doe"}',
        "response-headers": '[{"Content-Type":"application/json"}, {"x-request-id":"dea576ed-ba18-4dd3-baa7-7c865c14b444"}]',
        "response-status": 200,
        "response-delay": 1000
    },
    method: "GET",
});

Credits

License

This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - see the LICENSE file for details