Geeks With Blogs

News This is the *old* blog. The new one is at blog.sixeyed.com
Elton Stoneman
This is the *old* blog. The new one is at blog.sixeyed.com

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:

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:

  • 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:

Host Response
404.badapi.net 404: NotFound
401.badapi.net 401: Unauthorized
503.badapi.net 503: Service Unavailable
400.badapi.net 400: Bad Request
409.badapi.net 409: Conflict
500.badapi.net 500: Internal Server Error
403.badapi.net 403: Forbidden

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

Full details in the live documentation: http://badapi.local/Help.

Posted on Friday, September 12, 2014 7:12 AM badapi.net | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: badapi.net just got badder

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net