# Axios

Axios is a Promise-based HTTP client widely used for data scraping, API calls, and more. Axios supports setting up a proxy server through its built-in proxy configuration option. Please follow the steps below to configure a proxy (this tutorial applies to the Node.js environment)

{% hint style="success" icon="lightbulb-exclamation-on" %}
Before configuring the proxy, you need to obtain proxies credentials. [Click here](/proxy/rotating-residential-proxies/quick-start.md) to learn how to obtain proxies credentials.
{% endhint %}

***

{% stepper %}
{% step %}

### **Install Axios**

Axios can be installed via various package managers depending on your project environment. Please visit the [Axios official documentation](https://axios-http.com/docs/intro) for detailed installation instructions. For example, using npm:

```http
npm install axios
```

{% endstep %}

{% step %}

### **Configure the Proxy**

In your code, you need to create a configuration object containing the proxy information. Replace the placeholders in the template below with your actual credentials:

```javascript
const proxyConfig = {
  host: 'your-proxy-host',  
  port: your-proxy-port,       
  protocol: 'http',       
  auth: {
    username: 'your-username', 
    password: 'your-password'
  }
};      
```

{% endstep %}

{% step %}

### **Use the Proxy in a Request**

Below is a complete example that sends a request to ipinfo.io (which returns the IP information of the request origin) using the configured proxy. Save this code in a file, for example `test-proxy.js`**.**

```javascript
const axios = require('axios');

// Your target URL, here we use http://ipinfo.io/
const targetUrl = 'http://ipinfo.io/';

const proxyConfig = {
  host: 'your-proxy-host',
  port: your-proxy-port,
  protocol: 'http',
  auth: {
    username: 'your-username',
    password: 'your-password'
  }
};

async function fetchData() {
  try {
    // Pass proxyConfig as an option to axios.get
    const response = await axios.get(targetUrl, { proxy: proxyConfig });
    console.log('Success:', response.data);
  } catch (error) {
    console.error('Fail:', error.message);
  }
}

fetchData();
```

{% endstep %}

{% step %}

### Verify the Proxy

In your terminal, navigate to the directory containing your JavaScript file (e.g., `test-proxy.js`) and run the following command (replace `test-proxy.js` with your actual filename if different):

```http
node test-proxy.js
```

If the proxy is configured correctly, you should see output similar to the following:

```javascript
Success: {
  ip: '203.0.113.45',
  city: 'Houston',
  region: 'Texas',
  country: 'US',
  loc: '29.7633,-95.3633',
  org: 'AS174 Cogent Communications, LLC',
  postal: '77002',
  timezone: 'America/Chicago',
  readme: 'https://ipinfo.io/missingauth'
}
```

{% endstep %}
{% endstepper %}

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.talordata.com/proxy/integrations/axios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
