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

How to correctly import Axios in vue 3 after creating new project with CLI?

I created a new project using: vue create hello-world Generating a new project that includes the HelloWorld.vue, app.vue, main.js (etc ...) files. Now I install Axios by following the docs Npm vue-axios: npm install --save axios vue-axios I import…
RDU
  • 812
  • 1
  • 9
  • 22
24
votes
1 answer

Using jest to mock multiple axios calls

I just found this useful way to mock axios using jest, however, if I have multiple calls to axios with different urls, how can I specify the url and the value to be returned depending on the url? Is there any way to do it without using 3rd party…
fgonzalez
  • 3,787
  • 7
  • 45
  • 79
24
votes
2 answers

Sec-Fetch-Mode instead of Preflight

I created login FE and finished it. And as per usual my goto for ajax was Axios. My code is as follows. const baseUrl = http://localhost:5000/project/us-central1/api Axios.post( `${baseUrl}/v1/user/login`, { ...data }, { headers: { …
Reyn
  • 757
  • 1
  • 5
  • 16
24
votes
1 answer

React - axios - blocked by CORS policy. How to unblock

I am running a simple API request to return data to a simple API search I've written. I say it's simple API call because there is no authentication needed and I can do it in python very simply. However, I am having issues when using Axios in…
Micah Pearce
  • 1,805
  • 3
  • 28
  • 61
24
votes
3 answers

Vue.js and Axios - redirect on 401

I'm running Vue.js and axios and are trying to make a generic API object like the following: import router from './router' import auth from './auth' const axios = require('axios') export const API = axios.create({ baseURL: `https://my-api.com/`, …
Alfred Balle
  • 1,135
  • 4
  • 16
  • 32
24
votes
6 answers

Using a setTimeout in a async function

I have a async function that waits for an axios call to complete before proceeding. The problem is that I need to put a timeout on the axios call to half a second so that I don't hit the shopify API call limit. async function…
24
votes
1 answer

Difference between NodeJS new Agent() and HTTP Keep-Alive header..?

I'm using axios to make HTTP requests. axios offers the option to specify new http.Agent() in the request config when used in Node. The http Agent options are: const agentOptions = { keepAlive: true, // Keep sockets around even when there are…
Stephen Last
  • 5,491
  • 9
  • 44
  • 85
24
votes
1 answer

How to implement a "before" callback in axios

I'm writing a project in Vue.js (using axios) with file upload functionality. I need to implement an action before the POST request is sent in axios: axios.post('/upload', form, { before: (xhr) => { fileObject.xhr = xhr; }, …
Kornel
  • 4,184
  • 4
  • 28
  • 30
24
votes
2 answers

Vue js 2 & Axios Post Request - Form

I am trying to post my form using axios, but I am not able to get the data to my backend using expressjs This is what I am doing: