badapi.net just got badder

Who’s bad?

The original release of 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.

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:

image

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:

image

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:

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:

HostResponse
404.badapi.net404: NotFound
401.badapi.net401: Unauthorized
503.badapi.net503: Service Unavailable
400.badapi.net400: Bad Request
409.badapi.net409: Conflict
500.badapi.net500: Internal Server Error
403.badapi.net403: Forbidden

And all those endpoints support GET, HEAD, POST, PUT and DELETE.

Full details in the live documentation:.

This article is part of the GWB Archives. Original Author: Elton Stoneman

New on Geeks with Blogs