HttpResponseSimulator Generate responses with a specific behaviour

What is this?

I you have a better name than HttpResponseSimulator just hit me up. It's just a tool that will allow you to define the behaviour you want a response to have. I built it over an afternoon so that I could write a test for an http client wrapper, to ensure timeouts would be handled properly since there was no way to reach the wrapped client directly. The first version came to life after an hour once I familiarized myself again with Node.js.

Eventually I added a few more advances over the past few days in order to make it a better tool. Now it serves a few more purposes than waiting a few seconds before responding. Then came the quality I needed to set before making it open-source and hopefully have people using it and helping it grow. And now it feels ready.

If you want to contribute you can send your ideas here or open pull requests there.

Supported inputs

The API is predictibly available at /api, don't blame my lack of creativity that started as an afternoon project. Below you can see the supported verbs and formats.

URL parameters Form JSON

Supported parameters

Key Type Action
wait Integer If positive, the response will be sent after waiting the specified value in milliseconds. (i.e. if the value is 200, the app will wait 200ms before responding)
pastebinId String If valid, the response will be the data matching that pastebin id.
echo String If set, the response will be the value passed.
responseUrl String If it is a valid and freely accessible url from a GET request, the data returned in the response will match the data you would get from that uri.
statusCode Integer If valid, will set the response status code.
accept String If valid, will set the response content type.


Get response from a pastebin id after 300 milliseconds

For the parameters request: wait=300&pastebinId=h5R3XNAj You will get the following response after waiting 300 milliseconds: I guess you know how to use the HttpResponseSimulator now.

Get a 500 error code with the default response handler response after 1 second.

For the parameters request: wait=1000&statusCode=500 You will get the following response after waiting 1 second: Waited 1000ms to respond. However if you trigger the same request through Postman, you can see the status code set to 500. 500 captured