Debuging API clients using http reverse proxies

While developing API clients it can often be helpfull to inspect the traffic that gets sent to the server. For HTTP APIs this can be easily achieved by using mitmproxy in reverse mode.

Mitmproxy is a HTTP proxy for “penetration testers and software developers”, it consists of multiple cli tools and also provides a webinterface. Installation instructions can be found here. In reverse mode the tool starts a HTTP server and redirects all requests to the upstream API.

 $ # if you want the cli interface (does not work on windows)
 $ mitmproxy --mode reverse:https://api.yourservice.com
 $ # for the webinterface
 $ mitmweb --mode reverse:https://api.yourservice.com

If the API url in the clients code is now changed to the proxy endpoint (http://localhost:8080 in most cases), the entire communication between the client and server can be monitored using either the cli or webinterface.