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

Axios interceptor in vue 2 JS using vuex

I store token after success login call in vuex store like this: axios.post('/api/auth/doLogin.php', params, axiosConfig) .then(res => { console.log(res.data); // token this.$store.commit('login', res.data); }) axiosConfig is…
BT101
  • 3,666
  • 10
  • 41
  • 90
33
votes
3 answers

How to get data to work when used within a component and Axios?

I'm new to Vue.js and Axios. I don't quite understand how to get the data option to work when used within a component. Why doesnt' my test work? I get the following error in the console: [Vue warn]: The "data" option should be a function that…
redshift
  • 4,815
  • 13
  • 75
  • 138
33
votes
4 answers

Flask-CORS not working for POST, but working for GET

I'm running a Flask-Restful API locally and sending a POST request containing JSON from a different port. I'm getting the error No 'Access-Control-Allow-Origin' header is present on the requested resource. However, when I run curl --include -X…
hatooku
  • 423
  • 1
  • 4
  • 11
32
votes
2 answers

How to setup Axios interceptors with React Context properly?

Since I want to setup Axios interceptors with React Context, the only solution that seems viable is creating an Interceptor component in order to use the useContext hook to access Context state and dispatch. The problem is, this creates a closure…
hakaman
  • 411
  • 1
  • 5
  • 8
32
votes
2 answers

Best Way to Pass Query Parameters to URL Using Axios in Vue?

What I am trying to accomplish is when the page first loads I will use Axios using the base URL to pull back a JSON object. I then want to add query parameters to the base URL when a button is clicked. So something along the lines of if the base URL…
user9664977
  • 789
  • 2
  • 15
  • 28
32
votes
2 answers

What is an axios cancel token?

https://github.com/axios/axios#cancellation I was looking at how to cancel an upload PUT request and came across this section in the documentation. Why do you need a token to cancel? What is the flow or process in simple terms? How is it used?
cocoPuffs
  • 639
  • 2
  • 6
  • 18
32
votes
4 answers

How to handle net::ERR_CONNECTION_REFUSED in Axios - Vue.js

Below is my connection request code : doLogin(this.login).then(response => { var token = response.data.token; localStorage.setItem('AUTH_TOKEN', JSON.stringify(token)); this.$router.push({name: 'Devices'}); }); …
Jithesh Kt
  • 2,023
  • 6
  • 32
  • 48
32
votes
1 answer

Axios expose response headers: Content-Disposition

I was able to set request headers to expose Content-Disposition by adding: "Access-Control-Expose-Headers": "Content-Disposition" I can see the response but the response object does not include Content-Disposition. Is there any way i can access…
pranay-91
  • 323
  • 1
  • 3
  • 9
32
votes
2 answers

Can I throw error in axios post based on response status

Is it possible to throw an error on purpose inside the .then() block in axios? For instance, if the api responds with 204 status code, could I throw an error and run the catch block? For example: axios.post('link-to-my-post-service', { …
jenny
  • 933
  • 2
  • 11
  • 26
30
votes
1 answer

Can I access state inside a createAsyncThunk w/axios with redux toolkit?

I'm fairly new to redux toolkit so I'm still having a few issues with it! As per the code below, I'm trying to access state (loginDetails.username and loginDetails.password) inside my createAsyncThunk. I'm obviously doing something wrong here - I've…
rizji
  • 323
  • 1
  • 3
  • 7
30
votes
2 answers

How to fix AXIOS_INSTANCE_TOKEN at index [0] is available in the Module context

I am using Axios in my project to call some third-party endpoints. I don't seem to understand the error Nest can't resolve dependencies of the HttpService (?). Please make sure that the argument AXIOS_INSTANCE_TOKEN at index [0] is available in…
techstack
  • 1,367
  • 4
  • 30
  • 61
30
votes
5 answers

How to use axios with a proxy server to make an https call?

It's basically the same question here. I'm using a browser. The following code is compiled by webpack. I tried this: const axios = require('axios'); var res = await axios.get('https://api.ipify.org?format=json', { proxy: { host:…
Sw0ut
  • 741
  • 2
  • 9
  • 29
29
votes
5 answers

axios Error typescript, annotation must be 'any' or 'unknown' if?

I got error of Catch clause variable type annotation must be 'any' or 'unknown' if specified.ts(1196) with below code import axios, { AxiosError } from "axios"; try { } catch(error: AxiosError) { throw Error(error); } How to…
Fay Chen
  • 521
  • 1
  • 4
  • 12
29
votes
8 answers

Best Practice in Error Handling in Vuejs With Vuex and Axios

I am using Vuex + axios, I want to know the best practice in handling errors for vuex + axios. What I am doing now is that when I request using axios and it returns an error, it will be committed in mutation and update my state. What I want to do…
LordGrim
  • 731
  • 2
  • 11
  • 22
29
votes
6 answers

How can I use axios in lambda?

Do I have to install the axios module locally and then deploy it to lambda or is there a way to do it through the inline code editor as well in the browser?
thedreamsaver
  • 1,294
  • 4
  • 16
  • 27