Who’s bad?

The original release of badapi.net was a bit limited – you could get whatever error response you needed, but only if you changed your client to point to the badapi.net URLs – so if you want to test that your client behaves differently when it gets a 500 from the server, you had to change the code to point to http://badapi.net/internalservererror.

With the new release (from commit 6ab647e), badapi.net now has dedicated host names for the common error responses, and they can take any URL. So now you can test your client in error situations without changing code, just by using a proxy and redirecting your API call to badapi.net.

Redirecting traffic - simple version

If you’re working within a local network, you can install Charles, the web debugging proxy, and do the redirects from there. From the Structure window in Charles, find the base URL for your API, and select Map Remote:

Now you can map all calls for you API to badapi.net at the domain level, so any resource request goes to badapi.net and gets a known error response:

badapi.net ignores the rest of the URL, so you can use one redirect for all your API calls. In this example, I’ve mapped api.myproduct.net to 503.badapi.net, so all these calls will get a 503 Service Unavailable response:

GET http://api.myproduct.net/resource/123

HEAD http://api.myproduct.net/resource/123

GET http://api.myproduct.net/resources?page=10&size=20

POST http://api.myproduct.net/resources

PUT http://api.myproduct.net/resource/123

DELETE http://api.myproduct.net/resource/123

Any devices on the same network where you’re running Charles can use your proxy, so you can point web browsers and tablets to the proxy machine and test their behaviour.

Redirecting traffic - more complicated version

If you don’t want to permanently run Charles on a machine, or you need to have a proxy that can span multiple networks, you need to do a bit more.

You can create a cloud VM somewhere and use that as your proxy server – or as your DNS server.

On that server you can set up a proxy or just rig the DNS so your API hosts get repointed to the badapi.net hosts.

Domain redirects

badapi.net has 7 hosts you can redirect to, to get known error responses: