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

Axios is not defined

I am using axios for building a simple weather app with React.js. I just completed the code but there is a problem. When I launch that app, it's not working at all and I see a reference error that says axios is not defined. Here is my…
user7628486
29
votes
2 answers

How does one set global headers in axios?

Hi I'm setting default axios headers in request interceptor but these headers are not accessible in another function... in axios axios documentation it is mentioned that global-axios-defaults are global...below is my sample code need…
code.king
  • 368
  • 1
  • 3
  • 10
29
votes
1 answer

Waiting for all promises called in a loop to finish

I'm using the axios promise library, but my question applies more generally I think. Right now I'm looping over some data and making a single REST call per iteration. As each call completes I need to add the return value to an object. At a high…
jkj2000
  • 1,563
  • 4
  • 19
  • 26
28
votes
1 answer

How to test useEffect with async function and setState inside

I have set up a github project to understand how to better test react (v 16.8.0) useEffect hook. I make an api call to fetch data inside useEffect and I set the received data as state component element. My component receives the query as a prop and…
delca85
  • 1,176
  • 2
  • 10
  • 17
28
votes
2 answers

How should I send JWT token in axios GET request?

I'm new to Vue.js and want to make a request in a component to a restricted api: computed: { token () { return this.$store.getters.getToken; }, ... created () { axios .get( this.BASE_URL + '/profile/me') …
Babr
  • 1,971
  • 14
  • 33
  • 47
28
votes
9 answers

Pass parameter/argument to axios interceptor

How do I send custom parameters to the axios interceptor? I am using an interceptor like this: window.axios.interceptors.request.use(function (config) { if (PASSED_PARAM == true) { doSomethingAwesome(); } return config; },…
Fredrik
  • 3,027
  • 8
  • 33
  • 66
28
votes
6 answers

axios post array data

I'm trying to send post request to a server I don't have much control on it. The only thing I know is I can obtain the correct response if I post the following data in Postman x-www-form-urlencoded radio button checked Entered the following 2 array…
Rick Lee
  • 743
  • 2
  • 7
  • 19
27
votes
3 answers

How to handle Axios timeout with hanging API server?

Having issues trying to get timeout method of axios working. For testing: I setup a intentionally bad API endpoint: it accepts a request, throws an error (Eg: throw new Error(“testing for timeout”)) and intentionally does nothing else. My client app…
andrew
  • 1,184
  • 3
  • 19
  • 28
27
votes
5 answers

How to fetch API data from Axios inside the getServerSideProps function in NextJS?

I'm building an App with Next.js, and I need to connect to specific API routes (set up with API Platform) and populate pages with the route's responses. The API is working fine, but no matter how I try to implement my Axios call inside the…
Arnauf
  • 271
  • 1
  • 3
  • 4
27
votes
7 answers

How can I read http errors when responseType is blob in Axios with VueJs?

I'm using blob responseType with Axios in my VueJS app for downloading a document from the server. When the response code is 200 it works fine and download the file but when there is any http error, I'm not able to read the status code when I catch…
Sai
  • 271
  • 1
  • 3
  • 6
27
votes
5 answers

How do I use axios within ExpressJS?

I want to be able to use my React app to make a GET request to my server, which is suppose to prompt my server to make an GET request to an external API. I'm using axios and tried using request but both are giving me ERRTIMEOUT. The request are…
mLjH
  • 425
  • 2
  • 7
  • 11
27
votes
4 answers

Nestjs using axios

This simple demo has an error https://docs.nestjs.com/techniques/http-module import { Get, Controller, HttpService } from '@nestjs/common'; import { AxiosResponse } from 'axios' import { Observable } from 'rxjs' @Controller() export class…
januw a
  • 2,056
  • 5
  • 18
  • 39
27
votes
3 answers

Make request to SOAP endpoint using axios

I need to make request to SOAP endpoint using axios in my React application. Hence I need to pass xml data in request and receive xml data in response. I have used the axios post with json data but how do I use the same for xml? PFB the code I am…
Peter
  • 10,492
  • 21
  • 82
  • 132
27
votes
1 answer

Know if there are pending request in axios

I'm new in ReactJS and for my ajax call I tried to use Axios library. It is awesome, but now I would like know if there is a way for know if there are pending requests in axios interceptor because, I would like, show loading overlay every ajax call…
LorenzoBerti
  • 6,704
  • 8
  • 47
  • 89
26
votes
6 answers

TypeError: func.apply is not a function

I'm trying to use useEffect function like that: const [data, setData] = useState({ courses: [] }); useEffect(async () => { const result = await axios.get( "http://example.com/api/v1/categories/" ); …
sundowatch
  • 3,012
  • 3
  • 38
  • 66