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

How to show progress of Axios during get request (not download or upload)

I want is to show a progressbar while Axios is getting my requests. axios package has both onDownloadProgress and onUploadProgress to show a progressbar during download or upload, but no progress bar during get request. I've searched a lot of…
Cédric Bloem
  • 1,447
  • 3
  • 16
  • 34
26
votes
2 answers

Change responseType in Axios based on response

I've an axios request with responseType: 'arraybuffer' this works correctly when response is a success 200. However when the api I'm accessing and returns a 500 with a json object - axios encodes that in an arraybuffer. My current workaround is to…
Alex Wachira
  • 1,225
  • 16
  • 19
26
votes
8 answers

How to get axios baseUrl in nuxt?

I have axios module in my Nuxt.js project. I also set up my baseUrl (for API) in localhost:4040/api while my client is running on port 3000. When I fetch image data in the API, it returns a relative path to the api server which is like…
Terry Djony
  • 1,975
  • 4
  • 23
  • 41
26
votes
3 answers

Axios ajax, show loading when making ajax request

I'm currently building a vue app and Im using axios. I have a loading icon which i show before making each call and hide after. Im just wondering if there is a way to do this globally so I dont have to write the show/hide loading icon on every…
Brad
  • 8,044
  • 10
  • 39
  • 50
26
votes
2 answers

Get notified after axios timeout

I have an API call using axios. A timeout is set for 2500 millis. What I want is axios to return a value after the timeout so I can notify to the user the request is aborted due to some server or network error. How I initialized the timeout const…
sajithneyo
  • 641
  • 3
  • 7
  • 17
26
votes
4 answers

axios.post is sending a GET request

I have a chrome extension which uses react/axios. In that app I'm sending a post request like so: export const createComment = payload => { const url = `${COMMENTS_BASE_URL}`; const promise = axios.post(url, payload); return { type:…
awwester
  • 9,623
  • 13
  • 45
  • 72
26
votes
7 answers

how to return response of axios in return

I want to return the response of axios but always the response that returned is undefined: wallet.registerUser=function(data){ axios.post('http://localhost:8080/register',{ phone:data.phone, password:data.password, email:data.email }).then(response…
Candy
  • 654
  • 2
  • 10
  • 24
25
votes
2 answers

What is the correct way to pass parameters to a React-query useQuery method that uses Axios

I am currently building a Ruby on Rails Webpacker application with a React front end. I am at the point where I would like to create all the quires I need to make calls to my Rails API. I was loosely following this tutorial…
humbledev7000
  • 275
  • 1
  • 4
  • 8
25
votes
6 answers

access token from auth0provider outside of react components

I'm using the auth0 token provided by the user on login to make api calls via useAuth0.getTokenSilently. In this example, fetchTodoList, addTodoItem, and updateTodoItem all require a token for authorization. I'd like to be able to extract these…
ItsGeorge
  • 2,060
  • 3
  • 17
  • 33
25
votes
3 answers

Axios config default GET param

I'm using Axios in my VueJS application and I want to add a default GET param in my request. I send my API-KEY through the URL ?api-key=secret and I don't want to specify this parameter each time. I see in the documentation that we can set Global…
John
  • 4,711
  • 9
  • 51
  • 101
25
votes
6 answers

GraphQL post request in axios

I have a problem with GraphQL. I want to send axios.post request to my server. I can do it in postman: { "query":"mutation{updateUserCity(userID: 2, city:\"test\"){id name age city knowledge{language frameworks}}} " } and in graphiql: mutation…
Tatevik
  • 375
  • 1
  • 4
  • 11
25
votes
4 answers

How to detect a 401 with axios and stop the console error

I am trying to use axios to call an API and return data. I have the following code which works fine axios.get('http://api/courses') .catch(function (error) { if (error.response) { console.log(error.response.status); } else { …
davidjh
  • 387
  • 1
  • 7
  • 13
25
votes
3 answers

SSL certificate - disable verification in axios and react

I'm trying to consume an API in my react application using axios. The API works over HTTPS with self signed certificate. So far I've got the following error when connecting: net::ERR_INSECURE_RESPONSE bundle.js:65253 HTTP Failure in Axios Error:…
Goranov
  • 355
  • 1
  • 3
  • 10
25
votes
5 answers

Disable JSON parsing in Axios

I have a react application in which I want the user to be able to upload code files that he can then view. So naturally, .json files are also accepted. Now to get the file contents, I use axios to make a get request to the file on the server. This…
LuLeBe
  • 414
  • 1
  • 5
  • 11
24
votes
4 answers

Casting dates properly from an API response in typescript

I have a REST API that gives data in the following format:- {"id": 1, "name": "New event", "date": "2020-11-14T18:02:00"} And an interface in my frontend React app like this:- export interface MyEvent { id: number; name: string; date:…
Babri
  • 739
  • 1
  • 7
  • 10