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
21
votes
4 answers

How to use JSONP on fetch/axios cross-site requests

I'm trying to do a GET request on wikipedia API. Using jQuery as below works fine: $.ajax({ url:…
Luan Scudeler
  • 441
  • 2
  • 5
  • 11
21
votes
4 answers

How to pass form values as FormData in reactjs on submit function

I have a dynamic form generated using json data and I need to pass the form input values on submit. I'm planning to send the values as formdata. I have created submit function but i don't know how to append the values in formdata and need to pass…
knbibin
  • 1,099
  • 7
  • 18
  • 36
21
votes
2 answers

cross domain at axios

I am changing jquery ajax for axios and I not getting use axios with cross domain: axios.get(myurl, { headers: { 'crossDomain': true }, }).then(res => { console.log(res); }).catch(error => { …
Alessander França
  • 2,697
  • 2
  • 29
  • 52
21
votes
4 answers

Encoding issue with Axios

I am fetching a web page with axios, but the content-type of the response is ISO-8859-1, and the result given by axios seems like it parses it as UTF-8 and the result has corrupt characters. I tried to convert the result encoding but nothing works,…
Iván Portilla
  • 461
  • 1
  • 3
  • 13
20
votes
4 answers

Cannot find name 'AbortSignal' during npm run build

node_modules/axios/index.d.ts:93:12 - error TS2304: Cannot find name 'AbortSignal'. 93 signal?: AbortSignal; ~~~~~~~~~~~ Found 1 error. When trying npm run build comand for node typescript project, i am getting above error,…
MUHAMMAD SHAHID RAFI C P
  • 1,067
  • 1
  • 12
  • 25
20
votes
3 answers

TypeError: adapter is not a function error when using axios and webpack in Chrome extension

I'm building a chrome extension which will need to make an API call when certain messages are received from the content script. I'm having difficulty making the HTTP request and I believe that my webpack configuration is to blame. I've tried using…
20
votes
5 answers

Material-table TypeError: Cannot add property tableData, object is not extensible

I'm using meterial-table with React. I'm trying to assign data from an array coming from an api like this Where columns and rows are api data. But I'm getting this error: TypeError: Cannot…
J. Doe 2018
  • 313
  • 3
  • 8
20
votes
3 answers

Axios.get().then() in a for loop

How would I go about running Axios in a for loop, each with a corresponding .then() function. Then after the for loop ends, run another function. Example: const array = ['asdf', 'foo', 'bar']; let users = []; for (i = 0; i < array.length; i++) { …
user1661677
  • 1,252
  • 5
  • 17
  • 32
20
votes
3 answers

form-data | axios: Unable to get headers from FormData, Error: getHeaders is not a function

I am trying to post text and file fields using form-data and axios, but I am getting an error: getHeaders() is not a function. Below is my submit code, note that I am using React with Typescript. import * as FormData from 'form-data' import axios…
acmoune
  • 2,981
  • 3
  • 24
  • 41
20
votes
3 answers

abort all Axios requests when change route use vue-router

how can i abort / cancel Axios request before complete when i change route use vue-router. when user open page it automatically send axios request to get some data, but user don't waiting to get response then he is changing route by vue-router it…
Ghyath Darwish
  • 2,614
  • 4
  • 15
  • 31
19
votes
4 answers

Property 'mockResolvedValue' does not exist on type '>

I'm trying to do the Mocking Module example on the Jest official documentation here: https://jestjs.io/docs/mock-functions test('should fetch users', () => { const users = [{name: 'Bob'}]; const resp = {data: users}; …
user2298581
  • 532
  • 3
  • 11
  • 37
19
votes
5 answers

AXIOS request: "Error: connect ECONNREFUSED 127.0.0.1:80"

Trying to understand what's going on with my GET request. I set this up on the backend using node.js. I first thought I was using the wrong .env, url, username, and password... but when I checked on Postman, Basic Auth seemed to be getting the JSON…
Etep
  • 2,721
  • 4
  • 17
  • 28
19
votes
1 answer

how to handle 500 error message with axios

I cannot get the response text in the 500 error with axios. in Network tab in dev tools i can find the error message like this {"Message":"500 error message 0","Code":0,"Type":"error"} and I use axios() .then(function(done) { //fine and can get…
COS LIM
  • 191
  • 1
  • 1
  • 4
19
votes
4 answers

Default query params not getting passed in axios request

I'm using axios.create() to pass in a baseURL and some default query params like this axios.create({ baseURL: 'http://somebigurlhere', params: { part: 'part', maxResults: 5, key: 'key' } }); When I use…
pallav_125
  • 211
  • 1
  • 2
  • 8
19
votes
4 answers

Axios catch error Request failed with status code 404

I'm testing a login component that uses Axios. I tried mocking Axios with axios-mock-adapter, but when I run the tests, it still errors out with: Error: Request failed with status code 404 How do I properly mock Axios in my…
priyeshvadhiya
  • 606
  • 3
  • 8
  • 27