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.

Filter by
Sorted by
Tagged with
580 votes
16 answers
772k views

How can I get the status code from an HTTP error in Axios?

This may seem stupid, but I'm trying to get the error data when a request fails in Axios. axios .get('foo.example') .then((response) => {}) .catch((error) => { console.log(error); //...
Sebastian Olsen's user avatar
453 votes
21 answers
1.1m views

axios post request to send form data

axios POST request is hitting the url on the controller but setting null values to my POJO class, when I go through developer tools in chrome, the payload contains data. What am I doing wrong? Axios ...
Srikanth Gowda's user avatar
450 votes
16 answers
1.2m views

How to set header and options in axios?

I use Axios to perform an HTTP post like this: import axios from 'axios' params = {'HTTP_CONTENT_LANGUAGE': self.language} headers = {'header1': value} axios.post(url, params, headers) Is this ...
user2950593's user avatar
  • 9,393
341 votes
12 answers
204k views

What is difference between Axios and Fetch? [closed]

I'm trying to call a web service for my application, and there are two options available: Fetch and Axios. I'm not sure which one to choose, so I'm looking for information to help me decide. Can you ...
Gorakh Nath's user avatar
  • 9,538
337 votes
15 answers
852k views

Axios handling errors

I'm trying to understand javascript promises better with Axios. What I pretend is to handle all errors in Request.js and only call the request function from anywhere without having to use catch(). In ...
mignz's user avatar
  • 3,788
332 votes
17 answers
297k views

Axios get access to response header fields

I'm building a frontend app with React and Redux and I'm using axios to perform my requests. I would like to get access to all the fields in the header of the response. In my browser I can inspect the ...
TWONEKSONE's user avatar
  • 4,098
329 votes
21 answers
676k views

Make Axios send cookies in its requests automatically

I am sending requests from the client to my Express.js server using Axios. I set a cookie on the client and I want to read that cookie from all Axios requests without adding them manually to request ...
Kunok's user avatar
  • 8,459
325 votes
19 answers
696k views

Sending the bearer token with axios

In my react app i am using axios to perform the REST api requests. But it's unable to send the Authorization header with the request. Here is my code: tokenPayload() { let config = { headers: ...
rakibtg's user avatar
  • 5,681
323 votes
10 answers
789k views

Passing headers with axios POST request

I have written an Axios POST request as recommended from the npm package documentation like: var data = { 'key1': 'val1', 'key2': 'val2' } axios.post(Helper.getUserAPI(), data) .then((...
Jagrati's user avatar
  • 11.8k
316 votes
9 answers
474k views

Attach Authorization header for all axios requests

I have a react/redux application that fetches a token from an api server. After the user authenticates I'd like to make all axios requests have that token as an Authorization header without having to ...
awwester's user avatar
  • 9,961
311 votes
10 answers
632k views

How to post a file from a form with Axios

Using raw HTML when I post a file to a flask server using the following I can access files from the flask request global: <form id="uploadForm" action='upload_file' role="form" method="post" ...
Don Smythe's user avatar
  • 9,524
288 votes
20 answers
528k views

Axios - DELETE Request With Request Body and Headers?

I'm using Axios while programming in ReactJS and I pretend to send a DELETE request to my server. To do so I need the headers: headers: { 'Authorization': ... } and the body is composed of var ...
Asfourhundred's user avatar
283 votes
20 answers
623k views

How to download files using axios

I am using axios for basic http requests like GET and POST, and it works well. Now I need to be able to download Excel files too. Is this possible with axios? If so does anyone have some sample code? ...
David Choi's user avatar
  • 6,349
272 votes
10 answers
472k views

How to send Basic Auth with axios

I'm trying to implement the following code, but something is not working. Here is the code: var session_url = 'http://api_address/api/session_endpoint'; var username = 'user'; var password = 'password'...
Emmanuel's user avatar
  • 3,067
249 votes
4 answers
437k views

Axios get in url works but with second parameter as object it doesn't

I'm trying to send GET request as second parameter but it doesn't work while it does as url. This works, $_GET['naam'] returns test: export function saveScore(naam, score) { return function (...
Sinan Samet's user avatar
  • 6,592
209 votes
4 answers
455k views

How to post query parameters with Axios?

I am trying to post on an API with some query params. This is working on PostMan / Insomnia when I am trying to by passing mail and firstname as query parameters : http://localhost:8000/api/mails/...
GuillaumeRZ's user avatar
  • 2,806
184 votes
3 answers
320k views

How to return values from async functions using async-await from function? [duplicate]

How can I return the value from an async function? I tried to like this const axios = require('axios'); async function getData() { const data = await axios.get('https://jsonplaceholder.typicode....
King Rayhan's user avatar
  • 2,411
181 votes
7 answers
285k views

How can you use axios interceptors?

I have seen axios documentation, but all it says is // Add a request interceptor axios.interceptors.request.use(function (config) { // Do something before request is sent return config; }, ...
Akash Salunkhe's user avatar
168 votes
6 answers
163k views

How to log all axios calls from one place in code

I am using axios for a react application and I would like to log all axios calls that I'm making anywhere in the app. I'm already using a single global instance of axios via the create function and I ...
David Choi's user avatar
  • 6,349
164 votes
7 answers
315k views

How do I test axios in Jest?

I have this action in React: export function fetchPosts() { const request = axios.get(`${WORDPRESS_URL}`); return { type: FETCH_POSTS, payload: request } } How do I test ...
Adear's user avatar
  • 2,005
153 votes
12 answers
370k views

How to send authorization header with axios

How can I send an authentication header with a token via axios.js? I have tried a few things without success, for example: const header = `Authorization: Bearer ${token}`; return axios.get(...
foobar's user avatar
  • 3,959
152 votes
6 answers
206k views

Download an image using Axios and convert it to base64

I need to download a .jpg image from a remote server and convert it into a base64 format. I'm using axios as my HTTP client. I've tried issuing a git request to the server and checking the response....
Hobbyist's user avatar
  • 16.1k
146 votes
12 answers
961k views

Axios having CORS issue

I added proxy in package.json and it worked great, but after npm run build the CORS issue has resurfaced again, does anyone know how to deal with CORS issue after npm run build in React. I have tried ...
Kiran's user avatar
  • 2,306
144 votes
20 answers
664k views

Access Control Origin Header error using Axios

I'm making an API call using Axios in a React Web app. However, I'm getting this error in Chrome: XMLHttpRequest cannot load https://example.restdb.io/rest/mock-data. No 'Access-Control-Allow-Origin' ...
SeaWarrior404's user avatar
137 votes
14 answers
175k views

Vue JS returns [__ob__: Observer] data instead of my array of objects

I've created a page where I want to get all my data from the database with an API call, but I'm kinda new to VueJS and Javascript aswell and I don't know where I'm getting it wrong. I did test it with ...
shawnest's user avatar
  • 1,399
135 votes
10 answers
241k views

how to cancel/abort ajax request in axios

I use axios for ajax requests and reactJS + flux for render UI. In my app there is third side timeline (reactJS component). Timeline can be managed by mouse's scroll. App sends ajax request for the ...
Rajab Shakirov's user avatar
133 votes
11 answers
451k views

Returning data from Axios API [duplicate]

I am trying to use a Node.JS application to make and receive API requests. It does a get request to another server using Axios with data it receives from an API call it receives. The second snippet is ...
bunkerguy's user avatar
  • 1,433
131 votes
12 answers
683k views

Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check

I have created trip server. It works fine and we are able to make POST request by Insomnia but when we make POST request by axios on our front-end, it sends an error: has been blocked by CORS policy: ...
GGG's user avatar
  • 1,417
129 votes
9 answers
388k views

How to configure axios to use SSL certificate?

I'm trying to make a request with axios to an api endpoint and I'm getting the following error: Error: unable to verify the first certificate It seems the https module, which axios uses, is unable to ...
Jemi Salo's user avatar
  • 3,581
126 votes
19 answers
199k views

How to correctly use axios params with arrays

How to add indexes to array in query string? I tried send data like this: axios.get('/myController/myAction', { params: { storeIds: [1,2,3] }) And I got this url: http://localhost/api/myController/...
Zin Kun's user avatar
  • 1,363
121 votes
17 answers
92k views

"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. ...
knirirr's user avatar
  • 2,500
120 votes
7 answers
136k views

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) { ...
Amol Aggarwal's user avatar
108 votes
5 answers
169k views

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 ...
mmraj's user avatar
  • 2,075
107 votes
14 answers
455k views

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 ...
Karim Taha's user avatar
  • 1,211
106 votes
7 answers
326k views

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 ...
Geoff's user avatar
  • 6,469
104 votes
3 answers
235k views

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 ...
Shamoon's user avatar
  • 42.4k
102 votes
3 answers
125k views

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 ...
Tim Wickstrom's user avatar
101 votes
8 answers
133k views

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 ...
Rizwan Ali's user avatar
  • 1,145
100 votes
12 answers
222k views

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 ...
Smith's user avatar
  • 1,268
96 votes
6 answers
240k views

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 ...
Amir Saleem's user avatar
  • 3,030
93 votes
7 answers
102k views

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://...
Markus Meskanen's user avatar
90 votes
13 answers
189k views

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('/...
ar099968's user avatar
  • 7,309
90 votes
19 answers
432k views

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&param2=${param2_id}` ) .then(function(response) { alert(); }) ....
Mirakurun's user avatar
  • 4,979
90 votes
2 answers
299k views

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"}]...
G. Debailly's user avatar
  • 1,241
86 votes
8 answers
134k views

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/...
Freddy's user avatar
  • 1,229
86 votes
8 answers
232k views

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 ...
shet_tayyy's user avatar
  • 5,587
86 votes
1 answer
305k views

Send object with axios get request [duplicate]

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 ...
Galivan's user avatar
  • 5,168
85 votes
2 answers
146k views

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 ...
Nane's user avatar
  • 803
84 votes
10 answers
88k views

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://...
steverb's user avatar
  • 1,495
84 votes
5 answers
254k views

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 ...
Mandakh's user avatar
  • 1,143

1
2 3 4 5
496