A friendly tip.

There are times in life where you need to deal with APIs. You probably don’t want to, but you have to (but you don’t want to). For the major part of you, this is everyday life. And most of the times, debugging what happens when you issue the network request and when you receive the response is a pain that you likely would leave to your colleagues.

Yes, because how many times you struggled to figure out that the API call was not working because the encoding was wrong? Or because an HTTP header was missing? And if you have a backend guy to deal with, he surely goes like “Are you sure you are doing [random_stuff]?”

And no, you simply can’t answer “I sure am!”, because you’re not that sure after all. It’s not easy to see what the final request looks like, and the same goes for the response.

When in doubt, use a proxy

There is a boatload of different solutions and approaches to this problem, but what I’m about to suggest is the fastest, easiest and most feasible way I could find to do it.

Since debugging the HTTP requests and responses is quite cumbersome (even more cumbersome for HTTPS), the best tool you can use in this case is a proxy. Of course, you already know what a proxy is, so I won’t be dwelling into its definition.

Among hundreds of proxies that vary in use, features, OS compatibility, how to choose the right one? I’d say, go simple. Meet mitmproxy.

mitmproxy

I can’t even begin to tell you how handy and amazing this little tool is. mitmproxy is “an interactive, SSL-capable man-in-the-middle proxy for HTTP with a console interface”. Yes, you operate it via console. Yes, it supports HTTPS. Yes, it allows “traffic flows to be intercepted, inspected, modified and replayed”. And yes, it is cross platform, since it is written in Python. Did I mention it is completely free?

Using it is utterly simple, too. Once you install it, fire it up by typing the following command in your console:

$ mitmproxy [-b IP_ADDR] [-p PORT]

The proxy is now running, allowing you to intercept the network traffic. The next step involves configuring your device to redirect all the traffic to that proxy address (IP_ADDR + PORT).

The “Proxy Settings” app

Configuring the proxy settings on your Android device is, guess what, not so straightforward as you might want. You need to 1) go to the device’s Wi-Fi settings, then 2) long-press on the currently connected network, 3) choose to modify its settings, 4) show the advanced options, 5) enable the proxy settings and manually 6) type in the IP address and the port. The same goes for disabling it. This is nuts!

Thanks to Proxy Settings, the hassle of all this almost goes away. This lightweight application allows you to enable/disable the proxy settings for your network connection, all in the blink of a click.