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
42
votes
3 answers

Get response from axios with await/async

I'm trying to get JSON object from axios 'use strict' async function getData() { try { var ip = location.host; await axios({ url: http() + ip + '/getData', method: 'POST', timeout: 8000, …
IgorM
  • 1,348
  • 1
  • 12
  • 28
41
votes
3 answers

reactjs axios interceptors how dispatch a logout action

How can dispatch a logout action in case of status 401/403 with this code import axios from "axios"; import { Storage } from "./utils/storage"; const instance = axios.create({ baseURL: process.env.API_URL, timeout: 3000 }); const…
Whisher
  • 31,320
  • 32
  • 120
  • 201
41
votes
6 answers

Axios POST request fails with error status code 500: Internal Server error

I'm trying to send a POST request locally with a username and password in the body through Axios. I'm deploying a Flask app on http://127.0.0.1:5000/login, which handles the /login route. The POST request fails with the following error POST…
M Xiao
  • 553
  • 1
  • 7
  • 14
41
votes
6 answers

Missing headers in Fetch response

I need to make a CORS post request. I need to use fetch because axios's response is already processed to json. But in fetch response, the headers is empty. But I don't think this is the server problem since axios response headers have the values…
william
  • 7,284
  • 19
  • 66
  • 106
41
votes
7 answers

Post form data with axios in Node.js

I'm testing out the Uber API on Postman, and I'm able to send a request with form data successfully. When I try to translate this request using Node.js and the axios library I get an error. Here is what my Postman request looks like: The response…
Mike
  • 2,633
  • 6
  • 31
  • 41
40
votes
7 answers

Mock inner axios.create()

I'm using jest and axios-mock-adapter to test axios API calls in redux async action creators. I can't make them work when I'm using a axios instance that was created with axios.create() as such: import axios from 'axios'; const {…
kyw
  • 6,685
  • 8
  • 47
  • 59
39
votes
8 answers

How to get response times from Axios

Can anyone suggest any ways to get response times from Axios? I've found axios-timing but I don't really like it (controversial, I know). I'm just wondering if anyone else has found some good ways to log response times.
rozza
  • 927
  • 2
  • 11
  • 24
39
votes
4 answers

How to use 2 instances of Axios with different baseURL in the same app (vue.js)

I'm trying to learn vue.js so I made a little app that displays news articles from an API and, in another view, allows the user to log into another server. For this I'm using Axios. I know I got it to work pretty well at some point, but today when…
manu
  • 1,059
  • 1
  • 16
  • 33
39
votes
6 answers

axios gives me converting circular structure to json error while sending the data

My code is as shown below: axios.post('https://api.sandbox.xyz.com/v1/order/new', JSON.stringify({ "request": "/v1/order/new", "nonce": 123462, "client_order_id": "20150102-4738721", "symbol":…
Mrugesh
  • 4,381
  • 8
  • 42
  • 84
38
votes
2 answers

How to use Vue.prototype or global variable in Vue 3?

Like the title, I want to add Axios into Vue prototype. So when I want to use it, I can use it like this.$axios instead of importing it every time. CODE: //plugins/axios.ts import axios from 'axios' import router from '../router/index' const…
R.Q
  • 383
  • 1
  • 3
  • 7
38
votes
1 answer

"The final argument passed to useEffect changed size between renders", except I don't think it does?

I don't think I've ever received this error before: The final argument passed to useEffect changed size between renders. The order and size of this array must remain constant. I've done axios requests in useEffect() 100 times, using useEffect() in…
Chris Foster
  • 391
  • 1
  • 3
  • 3
38
votes
8 answers

How to use axios to make an https call?

I am trying to use axios with a proxy server to make an https call: const url = "https://walmart.com/ip/50676589" var config = { proxy: { host: proxy.ip, port: proxy.port } } axios.get(url, config) .then(result => {}) .catch(error =>…
etayluz
  • 15,920
  • 23
  • 106
  • 151
37
votes
1 answer

How to ignore SSL certificate validation in node requests?

I need to disable peer SSL validation for some of my https requests using node.js Right now I use node-fetch package which doesn't have that option, as far as I know. That should be something like CURL's CURLOPT_SSL_VERIFYPEER => false,…
Dmitry Samoylov
  • 1,228
  • 3
  • 17
  • 27
37
votes
6 answers

Download PDF from http response with Axios

I am working on a Vue application with a Laravel back-end API. After clicking on a link I would like to do a call to the server to download a certain file (most of the time a PDF file). When I do a get request with axios I get a PDF in return, in…
Giesburts
  • 6,879
  • 15
  • 48
  • 85
37
votes
9 answers

Axios: how to cancel request inside request interceptor properly?

I want to cancel the request if there's no token, so I do like this: instance.interceptors.request.use(config => { if (!getToken()) { console.log("interceptors: no access token"); } else { config.headers.Authorization = "Bearer " +…
TotalAMD
  • 887
  • 1
  • 10
  • 20