Proxy locations

Europe

North America

South America

Asia

Africa

Oceania

See all locations

Network statusCareers

Proxy Integration With Axios

Axios is a popular open-source JavaScript library that facilitates HTTP requests from the browser and a Node.js environment. The tool features the automatic transformation of JSON data, efficient management of HTTP headers, and the ability to cancel requests conveniently. 

This short blog post will demonstrate how to implement Oxylabs Datacenter and Residential Proxies with the Axios platform.  

axios integration with Oxylabs proxies

Installing Axios

Axios can be installed using any Javascript package manager such as npm, Yarn, Bower, etc. For example, to install it using npm, you can simply run the following command:

npm install axios

You can also install it using CDN as shown below:

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

If you’re using a different package or an alternative CDN, please refer to Axios’ official documentation

Setting up proxies

Axios offers the ability to integrate it with proxy servers. Let’s take a look at the code snippet below: 

const browser = require('axios')

browser.get('https://example.com',

   {

       proxy: {

           protocol: 'http',

           host: '<host_address>',

           port: <port_number>

       }

   }

).then(result => {

       console.log(result.data)

   }).catch(error => console.error(error))

The code is pretty straightforward – first, we instantiate a browser object using the Axios library. Then, we’re making a GET request to the website: example.com. Notice, when we’re making the GET request, we’re also passing a dictionary with the proxy information. Inside the dictionary, we are passing the protocol, host, and port to properly identify which proxy to use.

Residential Proxies

To use Oxylabs' Residential Proxies, we’ll have to slightly modify the above code, updating the information as shown below:

proxy: {

           protocol: 'http or https',

           host: 'pr.oxylabs.io',

           port: 7777,

           username: 'USERNAME',

           password: 'PASSWORD',

       }

The host address is now set to pr.oxylabs.io, the port is set to 7777, and the protocol is either HTTP or HTTPS. Also, you’ll have to update the credentials with your own – you can set up your proxy sub-user's credentials in our dashboard.  

Datacenter Proxies

If you’re using Shared Datacenter Proxies, fill in the information as shown below: 

proxy: {

           protocol: 'http only',

           host: 'dc.pr.oxylabs.io',

           port: 10000,

       }

If you’re using Dedicated Datacenter Proxies, insert your unique IP address in the host field and enter 60000 in the port field. 

Note: For additional Oxylabs’ proxy customization options – such as country-specific entry points – refer to Shared Datacenter, Dedicated Datacenter, and Residential Proxies documentations, respectively.

Testing proxy connection

Finally, let’s put the proxy integration to the test and see if the connection was successful. You can navigate to the ip.oxylabs.io website and see if your original IP address was changed with that of a proxy server. Check out the code given below:

const browser = require('axios')

browser.get('https://ip.oxylabs.io',

   {

       proxy: {

           protocol: 'http',

           host: 'pr.oxylabs.io',

           Port: 7777,

           username: 'USERNAME',

           password: 'PASSWORD',

       }

   }

).then(result => {

       console.log(result.data)

   }).catch(error => console.error(error))

The code above showcases the connection to a Residential Proxy. 

Note: make sure to update the code using your own credentials and proxy server information. 

Conclusion

Robust Oxylabs’ proxies allow developers to use Axios with enhanced anonymity and security, while protecting them from IP blocks. 

If you have any questions regarding Oxylabs proxy server integration with Axios, don’t hesitate to get in touch with our team for more information.

Please be aware that this is a third-party tool not owned or controlled by Oxylabs. Each third-party provider is responsible for its own software and services. Consequently, Oxylabs will have no liability or responsibility to you regarding those services. Please carefully review the third party's policies and practices and/or conduct due diligence before accessing or using third-party services.

Get the latest news from data gathering world

I'm interested

Get Axios proxies just for $15/GB