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
37
votes
6 answers

How do you send images to node js with Axios?

Is there a way to send an array of images (or a single image) to node using axios? The axios code I'm using(I'm using react js on the front end): onFormSubmit(event){ event.preventDefault(); let payload = this.state; console.log("in…
J. Bones
  • 459
  • 1
  • 5
  • 9
37
votes
2 answers

How to prevent Axios from encoding my request parameters?

I'm trying to pass in an API key through the URL parameters in my GET request. However, I notice that Axios encodes the characters in my API key when sending the request. This causes the API to reject my request as it couldn't recognise my key.…
Carven
  • 14,988
  • 29
  • 118
  • 161
36
votes
2 answers

TypeError: resolver is not a function

I am attempting to create a basic post on click in my NextJS app to a MongoDB database. The issue i am getting is TypeError: resolver is not a function. I understand it might be a syncronicity issue but for the life of me I cannot figure out…
Valentin
  • 1,371
  • 1
  • 11
  • 15
36
votes
3 answers

How should I test React Hook "useEffect" making an api call with Typescript?

I'm writing some jest-enzyme tests for a simple React app using Typescript and the new React hooks. However, I can't seem to properly simulate the api call being made inside the useEffect hook. useEffect makes the api call and updates the useState…
Matt Berg
  • 499
  • 1
  • 4
  • 10
36
votes
14 answers

Network error with axios and react native

I have created an API endpoint using the Django python framework that I host externally. I can access my endpoint from a browser (mydomain.com/endpoint/) and verify that there is no error. The same is true when I run my test django server on locally…
smilebomb
  • 5,123
  • 8
  • 49
  • 81
36
votes
13 answers

Getting 403 (Forbidden) when uploading to S3 with a signed URL

I'm trying to generate a pre-signed URL then upload a file to S3 through a browser. My server-side code looks like this, and it generates the URL: let s3 = new aws.S3({ // for dev purposes accessKeyId: 'MY-ACCESS-KEY-ID', secretAccessKey:…
Glenn
  • 4,195
  • 9
  • 33
  • 41
36
votes
5 answers

Jest returns "Network Error" when doing an authenticated request with axios

This seems a bit weird to me. I'm trying to test an actual (ie. real network) request with Jest. These are the tested scenarios: Test an external API (fixer.io) with no headers <--- This works Test a local API server with headers <--- This does…
lllllll
  • 4,715
  • 6
  • 29
  • 42
36
votes
12 answers

Axios (in React-native) not calling server in localhost

I'm building a really easy api and react-native application. The server works well (tested with PostMan) but the application doesn't call the server. It blocks when axios has to send the post request (see below). I'm desperate :-( Loosing too mush…
Pibo
  • 2,219
  • 2
  • 14
  • 23
35
votes
4 answers

use axios globally in all my components vue

I am testing with axios within a Vue application and the CLI. I've been using vue-resource and I could access it on all my components by simply passing it to Vue.use (VueResource). How can I achieve this with axios, so I do not have to import it…
FeRcHo
  • 1,119
  • 5
  • 14
  • 27
35
votes
1 answer

Axios: getting two requests OPTIONS & POST

I'm trying to post data. Everything works fine, but I don't know why I'm getting two requests OPTIONS & POST POST: OPTIONS: Here's the code: const url = 'http://rest.learncode.academy/api/johnbob/myusers'; export function postUsers(username,…
Liam
  • 6,517
  • 7
  • 25
  • 47
34
votes
5 answers

Handling api calls in Redux with Axios

Good evening everybody! I'm a total beginner in React and Redux so please bear with me if this sounds totally stupid. I'm trying to learn how I can perform some API calls in Redux and it's not going all to well. When I console log the request from…
Steinar
  • 451
  • 2
  • 7
  • 10
33
votes
5 answers

Vue Array converted to Proxy object

I'm new to Vue. While making this component I got stuck here. I'm making an AJAX request to an API that returns an array using this code: import axios from 'axios'; export default { data() { return { tickets: [], }; }, methods:…
Eduardo Robles
  • 495
  • 1
  • 5
  • 7
33
votes
1 answer

How to Handle Refresh Token When Multiple Requests are going out?

I am using reactjs, mbox and axios and ran into a problem. I have a api that gives out an access token and a refresh token. The access token dies every 20mins and when this happens the server sends a 401 back and my code will automatically send the…
chobo2
  • 83,322
  • 195
  • 530
  • 832
33
votes
8 answers

axios is not defined in vue js cli

I installed axios using the npm install axios command this is my package.json dependencies "dependencies": { "axios": "^0.18.0", "bootstrap-vue": "^2.0.0-rc.11", "vue": "^2.5.2", "vue-router": "^3.0.1" }, I registered the axios…
Beginner
  • 1,700
  • 4
  • 22
  • 42
33
votes
4 answers

NestJS returning the result of an HTTP request

In my NestJS application I want to return the result of an http call. Following the example of the NestJS HTTP module, what I'm doing is simply: import { Controller, HttpService, Post } from '@nestjs/common'; import { AxiosResponse } from…
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252