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
80
votes
2 answers

how to get onUploadProgress in axios?

I'm little bit confused that how to upload progress event with axios. Actually I am storing huge number files into aws s3. For that, how to get uploaded progress? I need this function onUploadProgress Currently my Post request is like this: export…
Nane
  • 2,370
  • 6
  • 34
  • 74
77
votes
12 answers

Python: FastAPI error 422 with POST request when sending JSON data

I'm building a simple API to test a database. When I use GET request everything works fine, but if I change to POST, I get 422 Unprocessable Entity error. Here is the FastAPI code: from fastapi import FastAPI app = FastAPI() @app.post("/") def…
Smith
  • 1,037
  • 1
  • 6
  • 15
77
votes
5 answers

Does Axios support Set-Cookie? Is it possible to authenticate through Axios HTTP request?

I'm trying to authenticate express API back-end using Axios HTTP request call. I was able to see 'Set-Cookie' in the response header, but cookie was not set. Is it possible to set cookies through Axios HTTP calls? Access-Control-Allow-Origin:…
Mandakh
  • 1,073
  • 1
  • 9
  • 10
76
votes
9 answers

CORS with Azure function from localhost (not CLI)

We are using axios in a vue.js app to access an Azure function. Right now we are getting this error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. We…
steverb
  • 1,415
  • 1
  • 10
  • 12
74
votes
13 answers

"Cannot use import statement outside a module" with Axios

I have a Vue.js application where two files contain: import axios from "axios" These files are located in src/lib within the application and include the import statement on their first line. Running tests on Github causes Axios 1.0.0 to be…
knirirr
  • 1,860
  • 4
  • 23
  • 37
74
votes
18 answers

Access to XMLHttpRequest at '...' from origin 'localhost:3000' has been blocked by CORS policy

Edit A little late, but I remember that I ended up solving this issue by setting credentials: true in my cors config on my backend. By complete accident, I noticed that if I set credentials: false in my axios client on the frontend, everything…
Mike K
  • 7,621
  • 14
  • 60
  • 120
73
votes
8 answers

Promise All with Axios

I just read an Article related to promise and was unable to comprehend how we can do multiple API call using Axios via Promise.all So consider there are 3 URL, lets call it something like this let URL1 = "https://www.something.com" let URL2 =…
Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
73
votes
3 answers

Axios. How to get error response even when api return 404 error, in try catch finally

for e.g. (async() => { let apiRes = null; try { apiRes = await axios.get('https://silex.edgeprop.my/api/v1/a'); } catch (err) { console.error(err); } finally { console.log(apiRes); } })(); in finally, apiRes will return null.…
Jacob Goh
  • 19,800
  • 5
  • 53
  • 73
73
votes
18 answers

'Access-Control-Allow-Origin' issue when API call made from React (Isomorphic app)

I'm running into an issue with my isomorphic JavaScript app using React and Express. I am trying to make an HTTP request with axios.get when my component mounts componentDidMount() { const url =…
Scott Davidson
  • 995
  • 1
  • 9
  • 12
70
votes
8 answers

How to catch and handle error response 422 with Redux/Axios?

I have an action making a POST request to the server in order to update a user's password, but I'm unable to handle the error in the chained catch block. return axios({ method: 'post', data: { password: currentPassword, new_password:…
Phillip Boateng
  • 1,111
  • 1
  • 12
  • 16
69
votes
12 answers

Axios - How to read JSON response?

Axios 0.17.1 .then(function (response) { console.log(response); //console.log(response.status); //It is an error -> SyntaxError: Unexpected token u in JSON at position 0 …
Mahesh
  • 1,503
  • 3
  • 22
  • 33
69
votes
3 answers

How to make axios synchronous

I'm using axios to check if an alias has not already been used by another in the database. Problem: The ajax call doesn't wait for the server response to execute the remaining code. The code looks like : export default { data () { return…
Warrio
  • 1,853
  • 4
  • 28
  • 45
66
votes
1 answer

how does axios handle blob vs arraybuffer as responseType?

I'm downloading a zip file with axios. For further processing, I need to get the "raw" data that has been downloaded. As far as I can see, in Javascript there are two types for this: Blobs and Arraybuffers. Both can be specified as responseType in…
lhk
  • 27,458
  • 30
  • 122
  • 201
66
votes
9 answers

How to retry 5xx requests using axios

I would like to retry 5xx requests using axios. I have my main request in the middle of a try catch block. I am using the axios-retry library to auto retry 3 times. The url i am using will deliberately throw a 503. However the request is not being…
Kay
  • 17,906
  • 63
  • 162
  • 270
65
votes
5 answers

How do I create configuration for axios for default request headers in every http call?

https://github.com/MrFiniOrg/AxiosQuestion I would like to have my project setup so that I do not have to specify the same request header in every http call. I have searched this online but I have not been able to accomplish this in my…
UncleFifi
  • 825
  • 1
  • 6
  • 9