Using a proxy with RestClient

Taci Shlosberg
3 min readOct 8, 2020

For the project I am currently working on I used Charles Proxy to monitor my HTTP requests. Charles is described on their website as:

Charles is a web proxy (HTTP Proxy / HTTP Monitor) that runs on your own computer. Your web browser (or any other Internet application) is then configured to access the Internet through Charles, and Charles is then able to record and display for you all of the data that is sent and received.

In other words, proxy server is a middleman that sits between the client and the primary server.

During my time in a coding bootcamp, I have never had to interact with external APIs until my final project. APIs (application programming interface) connect software and allow services to communicate and data to be transferred.

Given that some APIs in web app bridge communication between the front and backend, when something is going wrong it’s important to know which side is causing an error. If the app is not loading data correctly from the backend, the first thing we probably do is inspect the API request and response. If you are in Chrome, we do so by opening Chrome DevTools.

However, what happens when we want to capture HTTP requests from other non-browser apps? Here’s where a proxy comes into play. A proxy server intercepts and records HTTP traffic between backend systems

To use proxy you’ll need to install the software and run it on your local machine. Click here to install Charles.

When you start using Charles, you’ll notice that all the web traffic is routed through Charles. By default, Charles will start intercepting all Mac OS traffic. However, you can disable that and only display traffic that is manually configured to be sent through the proxy server. In my case, it was localhost:8888.

I wanted to check if my RestClient requests to external urls were successful or not. In case they were bad requests, I wanted to see the message value to help me fix the problem. When my server returned a 400 Bad Request I wasn’t sure where in the code the error was just by reading the error in the terminal. By inspecting on Charles proxy, I knew where to look to fix it. Below is a comparison of the message in my terminal vs Charles proxy.

Terminal
Charles Proxy

Using proxies with RestClient

To configure RestClient to use proxy, all you need to do is to set the proxy address to localhost and a default port. For example:

RestClient.proxy = “http://localhost:8888".

This is all about Charles. Another API tool you can use is Postman. Postman in my opinion has a better layout but I still need to configure Postman to work through proxy. Once I do I’ll update this blog post.

--

--