Make API calls with Axios using proxy

Rohan Hemnani
2 min readMay 14, 2021

Today, we will see how we can make HTTP API calls in node js using Axios client with proxy.

Why do we want to use proxy in API calls?

An API proxy is an interface that sits between your frontend and the actual backend services. Using a proxy in API decouples the frontend from implementation details of the backend, and allows you to create a custom interface that the frontend will interact with instead of the backend itself. Some reasons to use an API proxy include the ability to perform data transformations, hide complex calls to multiple services, and cache large or slow results.

In most organizations, when our code gets deployed into production we often require to make API calls using a proxy host. Let us see in a simpler way what exactly means to make API requests using a proxy.

Whenever we make any request to any API in our application, it directly sends a request to API from our application.

But when we use proxy in our code, the proxy becomes the facade that you put in your API so instead of calling API directly, an application calls the proxy and the proxy calls the API, and likewise API respond backs to API Proxy which in return gives response to your application. All the traffic between your application and API flows through the proxy. Proxies enable you to do things like secure your API, prevent denial of service attacks, and transform message content, etc. using different programming languages.

Below is the simplest, tried, and tested node js code for calling API with proxy using Axios.

For more information and code, follow and download the code from GitHub: https://github.com/Rohan009/axios-proxy-api

--

--

Rohan Hemnani

Full Stack Developer | Programmer | AWS | Enthusiast learner