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
111
votes
7 answers

catching error body using axios post

I am sending a status code 422 from my backend code with response body which contains the description of the error. I am using axios post as below to post a request: post: function(url, reqBody) { const request = axios({ baseURL:…
Amol Aggarwal
  • 2,674
  • 3
  • 24
  • 32
103
votes
3 answers

How do I set multipart in axios with react?

When I curl something, it works fine: curl -L -i -H 'x-device-id: abc' -F "url=http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" http://example.com/upload How do I get this to work right with axios? I'm using react if that matters: uploadURL…
Shamoon
  • 41,293
  • 91
  • 306
  • 570
101
votes
14 answers

How can I add raw data body to an axios request?

I am trying to communicate with an API from my React application using Axios. I managed to get the GET request working, but now I need a POST one. I need the body to be raw text, as I will write an MDX query in it. Here is the part where I make the…
Karim Taha
  • 1,151
  • 3
  • 9
  • 14
99
votes
5 answers

Axios Http client - How to construct Http Post url with form params

I am trying to create a postHTTP request with some form parameters that are to be set. I am using the axios with node server. I already have a java code implementation of constructing a url as given below: JAVA CODE: HttpPost post = new…
mmraj
  • 1,875
  • 4
  • 16
  • 19
96
votes
3 answers

Axios Interceptors retry original request and access original promise

I have an interceptor in place to catch 401 errors if the access token expires. If it expires it tries the refresh token to get a new access token. If any other calls are made during this time they are queued until the access token is…
Tim Wickstrom
  • 5,476
  • 3
  • 25
  • 33
96
votes
6 answers

Change the default base url for axios

I have configured my axios like this const axiosConfig = { baseURL: 'http://127.0.0.1:8000/api', timeout: 30000, }; Vue.prototype.$axios = axios.create(axiosConfig) Inside my component, I make a call as this.$axios.get('items').then().. Now…
Geoff
  • 6,277
  • 23
  • 87
  • 197
92
votes
6 answers

How to handle 401 (Authentication Error) in axios and react?

I have one file request.js which contains wrapper for axios ajax request. I am calling request function from multiple react components and when one of the request fails I want to refresh the token and retry all the failed requests again. I can use…
Amir Saleem
  • 2,912
  • 3
  • 21
  • 35
91
votes
7 answers

Multiple fields with same key in query params (axios request)?

So the backend (not under my control) requires a query string like this: http://example.com/?foo=5&foo=2&foo=11 But axios uses a JS object to send the request params: axios.get('http://example.com/', { foo: 5 }); And obviously an object can't have…
Markus Meskanen
  • 19,939
  • 18
  • 80
  • 119
86
votes
13 answers

node.js axios download file stream and writeFile

i want download a pdf file with axios and save on disk (server side) with fs.writeFile, i have tried: axios.get('https://xxx/my.pdf', {responseType: 'blob'}).then(response => { fs.writeFile('/temp/my.pdf', response.data, (err) => { if…
ar099968
  • 6,963
  • 12
  • 64
  • 127
86
votes
8 answers

Axios: chaining multiple API requests

I need to chain a few API requests from the Google Maps API, and I'm trying to do it with Axios. Here is the first request, which is in componentWillMount() axios.get('https://maps.googleapis.com/maps/api/geocode/json?&address=' + this.props.p1) …
Freddy
  • 1,229
  • 2
  • 13
  • 22
85
votes
7 answers

Timeout feature in the axios library is not working

I have set axios.defaults.timeout = 1000; I stopped the server that provides me with the APIs. But it takes more than 1s to timeout after sending a request. This is how my request looks: import axios from 'axios'; axios.defaults.timeout =…
shet_tayyy
  • 5,366
  • 11
  • 44
  • 82
83
votes
6 answers

failed to load response data request content was evicted from inspector cache

i am trying to get file from server that has size of(15mb) through Axios Request. showing status "200", but not sending file previewData(base64) and showing this error "failed to load response data request content was evicted from inspector cache"…
Rizwan Ali
  • 955
  • 2
  • 5
  • 7
83
votes
17 answers

React: Axios Network Error

This is my first time using axios and I have encountered an error. axios.get( `http://someurl.com/page1?param1=1¶m2=${param2_id}` ) .then(function(response) { alert(); }) .catch(function(error) { console.log(error); …
Mirakurun
  • 4,859
  • 5
  • 16
  • 32
82
votes
2 answers

React and TypeScript—which types for an Axios response?

I am trying to present a simple user list from an API which returns this: [{"UserID":2,"FirstName":"User2"},{"UserID":1,"FirstName":"User1"}] I do not understand fully how to handle Axios responses with types. The TypeScript error is Type '{} | {…
G. Debailly
  • 1,121
  • 1
  • 10
  • 13
82
votes
1 answer

Send object with axios get request

I want to send a get request with an object. The object data will be used on the server to update session data. But the object doesn't seem to be sent correctly, because if I try to send it back to print it out, I just get: " N; " I can do it with…
Galivan
  • 4,842
  • 9
  • 44
  • 76