Questions tagged [axios]

Axios is a Promise-based HTTP client for JavaScript which can be used in your front-end application and in your Node.js backend.

Promise based HTTP client for the browser and Node.js, available on Github.

Features

  • Make XMLHttpRequest from the browser
  • Make HTTP requests from Node.js
  • Supports the Promise API
  • Intercept request and response
  • Transform request and response data
  • Automatic transforms for JSON data
  • Client side support for protecting against XSRF

Installation

Using npm:

npm install axios

Using bower:

bower install axios

Using yarn:

yarn add axios

Using jsDelivr CDN:

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

Using unpkg CDN:

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
24271 questions
48
votes
7 answers

Automating access token refreshing via interceptors in axios

We've recently discussed an axios' interceptor for OAuth authentication token refresh in this question. What the interceptor should do is intercept any response with the 401 status code and try to refresh the token. With that in mind, the next thing…
Dawid Zbiński
  • 5,521
  • 8
  • 43
  • 70
47
votes
13 answers

React Proxy error: Could not proxy request /api/ from localhost:3000 to http://localhost:8000 (ECONNREFUSED)

I have a React frontend that uses jwt to authenticate with the Django backend. The backend works and is connecting just fine using django views, but when I try to proxy a request from React, it gives me a Connection Refused error. Proxy error:…
cclloyd
  • 8,171
  • 16
  • 57
  • 104
47
votes
4 answers

Progress Bar with axios

I have to display the upload status of the file using a Progress Bar. I am using axios to make http requests. I followed the example from their github page https://github.com/mzabriskie/axios/blob/master/examples/upload/index.html My code looks like…
Pritam Bohra
  • 3,912
  • 8
  • 41
  • 72
47
votes
2 answers

Axios can't set data

Here's my data: data: function(){ return { contas: [{id: 3, nome: "Conta de telefone", pago: false, valor: 55.99, vencimento: "22/08/2016"}] //debug test value }; }, And here's my get…
Guilherme Pressutto
  • 785
  • 2
  • 6
  • 18
46
votes
6 answers

Typescript Jest says mock or mockReturnedValue do not exist on types I wish to mock

Here's a class I wish to test: //Request.js import axios, {AxiosInstance} from 'axios'; import config from './config'; const axiosSingleton: AxiosInstance = axios.create({ baseURL: 'http://localhost:8080', }); export default class Request { …
Ashwini Raman
  • 936
  • 1
  • 7
  • 11
46
votes
7 answers

NodeJS, Axios - post file from local server to another server

I have an API endpoint that lets the client post their csv to our server then post it to someone else server. I have done our server part which save uploaded file to our server, but I can't get the other part done. I keep getting error { message:…
Tri Nguyen
  • 1,688
  • 3
  • 18
  • 46
46
votes
15 answers

Calling locally hosted server from Expo App

I am creating a react-native app and one of the components I have created contains a property which is populated through data coming from an http request. Right now I am hosting the server from my laptop, however I am testing the app on my phone…
iSeeJay
  • 783
  • 2
  • 6
  • 13
46
votes
12 answers

How to overcome the CORS issue in ReactJS

I am trying to make an API call through Axios in my React Application. However, I am getting this CORS issue on my browser. I am wondering if i can resolve this issue from a client side as i dont have any access to the API internally. Attached is my…
mohan babu
  • 1,388
  • 2
  • 17
  • 35
46
votes
5 answers

How to set state of response from axios in react

How do I set the state of a get response in axios? axios.get(response){ this.setState({events: response.data}) }
jordanpowell88
  • 857
  • 3
  • 11
  • 25
46
votes
2 answers

Axios interceptors and asynchronous login

I'm implementing token authentication. My access token expires every N minutes and then a refresh token is used to log in and get a new access token. I use Axios for my API calls. I have an interceptor set up to intercept 401…
Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
45
votes
3 answers

Error: Request body larger than maxBodyLength limit when sending base64 post request Axios

When sending a post request with a Base64 encoded pdf as the body i recieve the error Error: Request body larger than maxBodyLength limit I have tried setting both of the following 'maxContentLength': Infinity, 'maxBodyLength': Infinity in the…
user1781563
  • 685
  • 1
  • 5
  • 11
45
votes
11 answers

Axios - Remove headers Authorization in 1 call only

How can I remove the axios.defaults.headers.common.Authorization only in 1 call? I'm setting the default for all the calls to my domain but I have 1 call that I make on another domain and if the token is passed the call gives me an error, when…
user7021169
45
votes
11 answers

How to redirect from axios interceptor with react Router V4?

I want to make a redirection in axios interceptors when receiving a 403 error. But how can I access the history outside React components ? In Navigating Programatically in React-Router v4, it's in the context of a React Component, but here i'm…
hilderic sb
  • 593
  • 1
  • 4
  • 13
44
votes
7 answers

How to post multiple Axios requests at the same time?

At this moment I have a webpage in which a long list of Axios POST calls are being made. Now, the requests seem to be sent in parallel (JavaScript continues sending the next request before the result is received). However, the results seem to be…
Z0q
  • 1,689
  • 3
  • 28
  • 57
43
votes
7 answers

Handling Axios error in React

I have a React component that calls a function getAllPeople: componentDidMount() { getAllPeople().then(response => { this.setState(() => ({ people: response.data })); }); } getAllPeople is in my api module: export function…
GluePear
  • 7,244
  • 20
  • 67
  • 120