Introducing Slowwly: Slowing down api requests

#Programming, #Ruby

Here is a web application that is slow; slow by deliberate design.

Slowwly is a test service to mock a slow http response so that you can test how your application behaves when the really cool api that you rely on takes a bit longer to respond than you expect.

Slowwly application provides a slow response to api requests

So, there are already some cool projects doing this …but I want to see what happens when I made a POST request and I didn’t want to have to comment/uncomment tons of code to change the parameters sent. I also wanted the correct response to be received after the delay, it’s all very well testing failure but useful to see what happens when the correct thing happens, just slower.

As such the goals of Slowwly are such;

From GET requests we respond with 302 as normal, but from POST requests the status code is 307 along with the Location header as before. The 302 spec states that clients must make the subsequent request using GET but 307 implies that the original method can be used so the subsequent request will be the same as the original but to the correct Location.

The spec for HTTP 307 also says that clients should not automatically follow the redirect without confirmation so this may need some configuring on the client - also this is not a recommended design for an API; don’t use 307 unless you’ve got a good reason.

Checkout the project on github.

Example uses

Test slow asset loads

Test a webpage with slow loading asset such as an image by just prepending the Slowwly URL to the image.

<!-- example image -->
<img src="http://myassethost.com/image/foo.jpg">

<!-- see what happends when it takes 2 seconds to respond -->
<img src="http://slowwly.herokuapp.com/delay/2000/url/http://myassethost.com/image/foo.jpg">

Test API responses

You can use Slowwly to see how your application behaves with any http request, this is useful in several ways. You can see how a slow service impacts your application when the response is just delayed but also set the response time specifically so that you can test any circuit breaker type API code works correctly when handling timeouts.

Test a slow GET API response

Fetching some data from an API with a GET request? Here you can test how your application behaves when your code connects, but is slow to respond.

The HTTP response status returned is 302.

# a simple get request with 2.5 second delay
$ curl -i http://slowwly.herokuapp.com/delay/2500/url/http://myapi.com/resources/123
HTTP/1.1 302 Found
Content-Type: text/html;charset=utf-8
Location: http://myapi.com/resources/123
Content-Length: 0

Test a slow POST API response

We can also simulate a slow POST response mostly without having to change how you make the request - you can still post any parameters you want just prepend the Slowwly URL as before. You may need to configure the HTTP library in use to follow redirects, and preserve the method (althouth the response code should dictate this).

The HTTP response status returned is 307.

# a simple post request with 5 second delay
$ curl -i --data "param1=value1" http://slowwly.herokuapp.com/delay/5000/url/http://myapi.com/resources/123
HTTP/1.1 307 Temporary Redirect
Content-Type: text/html;charset=utf-8
Location: http://myapi.com/resources/123
Content-Length: 0

Rate / Hate / Contribute: rob-murray/slowwly.