axios

Axios Delete request with body and headers?

放肆的年华 提交于 2019-11-30 08:07:44
I'm using Axios while programing in ReactJS and I pretend to send a DELETE request to my server. To do so I need the headers: headers: { 'Authorization': ... } and the body is composed of var payload = { "username": .. } I've been searching in the inter webs and only found that the DELETE method requires a "param" and accepts no "data". I've been trying to send it like so: axios.delete(URL, payload, header); or even axios.delete(URL, {params: payload}, header); But nothing seems to work... Can someone tell me if its possible (I presume it is) to send a DELETE request with both headers and body

Automating access token refreshing via interceptors in axios

吃可爱长大的小学妹 提交于 2019-11-30 07:12:11
We've recently discussed an axios' interceptor for OAuth authentication token refresh in this question . Basically, what the interceptor should do is to intercept any response with 401 status code and try to refresh the token. With that in mind, the next thing to do is to return a Promise from the interceptor, so that any request which would have normally fail, would run as nothing happens after a token refresh. The main problem is, that an interceptor checks only the 401 status code, which is not enough, as the refreshToken will also return 401 status code when it fails - and we have a loop.

Axios Delete request with body and headers?

怎甘沉沦 提交于 2019-11-30 06:52:17
问题 I'm using Axios while programing in ReactJS and I pretend to send a DELETE request to my server. To do so I need the headers: headers: { 'Authorization': ... } and the body is composed of var payload = { "username": .. } I've been searching in the inter webs and only found that the DELETE method requires a "param" and accepts no "data". I've been trying to send it like so: axios.delete(URL, payload, header); or even axios.delete(URL, {params: payload}, header); But nothing seems to work...

How to make axios synchronous

…衆ロ難τιáo~ 提交于 2019-11-30 06:48:12
I'm using axios to check if an alias has not already been used by another in the database. Problem : The ajax call doesn't wait for the server response to execute the remaining code. The code looks like : export default { data () { return { id: null, alias: null, valid: true, } }, methods: { // triggered by the save button save () { this.valid = true; console.log('before checking'); this.checkUniqueness(); // other validations here if (this.valid) { console.log('3. checked valid, can save now'); // save now } }, checkUniqueness () { axios.get('/api/unique/alias', { params: { id: this.id, alias

Promise All with Axios

放肆的年华 提交于 2019-11-30 06:45:49
I just read an Article related to promise and was unable to comprehend how we can do multiple API call using Axios via Promise.all So consider there are 3 URL, lets call it something like this let URL1 = "https://www.something.com" let URL2 = "https://www.something1.com let URL3 = "https://www.something2.com" And an array in which we will store Value let promiseArray = [] Now, I want to run this in parallel ( Promise.all ), but I am unable to figure our how will we do it? Because axios have a promise in itself (or at-least that's how I have used it). axios.get(URL).then((response) => { })

Cant cancel Axios post request via CancelToken

Deadly 提交于 2019-11-30 05:26:54
问题 This code cancel GET requests but cant abort POST calls. If i send GET requests first and i dont cancel them via abortAll method,they just finish by themselves this token cancel by itself and doesnt work on next requests? What am i missing? Thanks,John import axios from 'axios' class RequestHandler { constructor(){ this.cancelToken = axios.CancelToken; this.source = this.cancelToken.source(); } get(url,callback){ axios.get(url,{ cancelToken:this.source.token, }).then(function(response){

Accessing VUE JS's data from Axios

烈酒焚心 提交于 2019-11-30 05:22:37
I have a Vue JS (Vuetify) App that makes an ajax request that I would like to populate a div's content with the response, however I am having difficulties accessing the instance's data . All examples I have seen use this to point to the data object, but when I do I get this error Unable to set property 'message' of undefined or null reference The app is quite simple: main.js : import Vue from 'vue' import App from './App.vue' import Vuetify from 'vuetify' Vue.use(Vuetify) new Vue({ el: '#app', render: h => h(App) }) App.vue export default { data () { return { .... message: '', order: {}, ... }

Jest returns “Network Error” when doing an authenticated request with axios

我的未来我决定 提交于 2019-11-30 04:42:42
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 NOT work Test same local API with headers from node terminal <--- This works What could be the reason behind this behavior? And what is the solution? //This WORKS test('testing no headers', () => { return axios.get('http://api.fixer.io/latest') .then( res => console.log(res) ) }); //This DOES NOT work test('testing no headers', () => { return axios.get(

Multiple Axios Requests Into ReactJS State

天涯浪子 提交于 2019-11-30 02:13:37
So I have been placing the following code within my React JS component and I am basically trying to put both API calls into one state called vehicles however I am getting an error with the following code: componentWillMount() { // Make a request for vehicle data axios.all([ axios.get('/api/seat/models'), axios.get('/api/volkswagen/models') ]) .then(axios.spread(function (seat, volkswagen) { this.setState({ vehicles: seat.data + volkswagen.data }) })) //.then(response => this.setState({ vehicles: response.data })) .catch(error => console.log(error)); } Now I am guessing I can't add two sources

Download an image using Axios and convert it to base64

╄→尐↘猪︶ㄣ 提交于 2019-11-30 01:24:46
I need to download a .jpg image from a remote server and convert it into a base64 format. I'm using axios as my HTTP client. I've tried issuing a git request to the server and checking the response.data however it doesn't seem to work like that. Link to axios: https://github.com/mzabriskie/axios Link to base64 implementation: https://www.npmjs.com/package/base-64 I'm using NodeJS / React so atob/btoa doesn't work, hense the library. axios.get('http://placehold.it/32').then(response => { console.log(response.data); // Blank console.log(response.data == null); // False console.log(base64.encode