axios

Returning data from Axios API

你离开我真会死。 提交于 2019-11-28 05:50:27
I am trying to use a Node.JS application to make and receive API requests. It does a get request to another server using Axios with data it receives from an API call it receives. The second snippet is when the script returns the data from the call in. It will actually take it and write to the console, but it won't send it back in the second API. function axiosTest () { axios.get(url) .then(function (response) { console.log(response.data); // I need this data here ^^ return response.data; }) .catch(function (error) { console.log(error); }); } ... axiosTestResult = axiosTest(); response.json(

ReactJS with React Router - strange routing behaviour on Chrome

浪尽此生 提交于 2019-11-28 05:38:40
问题 This is a bit weird and I would like to get to the bottom of it. I have a page where users type in their email address and click a button and then I show "you're signed up!" message - simple. For that, I have two routes. The main route and the "signed-up" route. <Route name="app" path="/" handler={Main}> <Route name="signed-up" path="signed-up" handler={SignedUp} /> <DefaultRoute handler={Signup} /> </Route> On the first page, when users type in the email address and click the button, I fire

Axios: chaining multiple API requests

我与影子孤独终老i 提交于 2019-11-28 05:24:05
I need to chain a few API requests from the Google Maps API, and I'm trying to do it with Axios. Here is the first request, which is in componentWillMount() axios.get('https://maps.googleapis.com/maps/api/geocode/json?&address=' + this.props.p1) .then(response => this.setState({ p1Location: response.data })) } Here is the second request: axios.get('https://maps.googleapis.com/maps/api/geocode/json?&address=' + this.props.p2) .then(response => this.setState({ p2Location: response.data })) Then we have a third request, which is dependent on the first two being completed: axios.get('https://maps

Sending the bearer token with axios

心不动则不痛 提交于 2019-11-28 04:38:23
In my react app i am using axios to perform the REST api requests. But it's unable to send the Authorization header with the request. Here is my code: tokenPayload() { let config = { headers: { 'Authorization': 'Bearer ' + validToken() } } Axios.post( 'http://localhost:8000/api/v1/get_token_payloads', config ) .then( ( response ) => { console.log( response ) } ) .catch() } Here the validToken() method would simply return the token from browser storage. All requests are having a 500 error response saying that The token could not be parsed from the request from the back-end. How to send the

How to set header and options in axios?

久未见 提交于 2019-11-28 03:22:24
I use axios to perform a HTTP post like this: import axios from 'axios' params = {'HTTP_CONTENT_LANGUAGE': self.language} headers = {'header1': value} axios.post(url, params, headers) Is this correct? Or should I do: axios.post(url, params: params, headers: headers) There are several ways to do this: For a single request: let config = { headers: { header1: value, } } let data = { 'HTTP_CONTENT_LANGUAGE': self.language } axios.post(URL, data, config).then(...) For setting default global config: axios.defaults.headers.post['header1'] = 'value' // for POST requests axios.defaults.headers.common[

Axios having CORS issue

霸气de小男生 提交于 2019-11-27 23:16:06
问题 I added proxy in package.json and it worked great, but after npm run build the CORS issue has resurfaced again, does anyone know how to deal with CORS issue after npm run build in React. I have tried to add headers in axios request using various methods. However, I failed to add 'Access-Control-Allow-Origin':'*' in axios request. My code is as follwing: package.json "proxy": { "*":{ "target" : "http://myurl"} } GetData.js axios.defaults.baseURL = 'http://myurl'; axios.defaults.headers.post[

Make request to SOAP endpoint using axios

蓝咒 提交于 2019-11-27 21:37:19
I need to make request to SOAP endpoint using axios in my React application. Hence I need to pass xml data in request and receive xml data in response. I have used the axios post with json data but how do I use the same for xml? PFB the code I am using for the same, but it does not work. JSON post request: var xmlData = <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> var config = { headers: {'Content-Type': 'text/xml'} }; axios.post('/save', xmlData, config); Please share if you have any experience with this, TIA. Anuragh KP

Is it possible to use axios.all with a then() for each promise?

与世无争的帅哥 提交于 2019-11-27 20:15:16
I have a React component that triggers an event to fetch data. This results in a dynamic number of stored proc calls to fetch data, and the data from each call is stored in a totally different location. Then I need to re-render once all of the data is received and available. I'm using promises with axios. Since the number of axios calls is dynamic, I'm building an array and inserting it into axios.all as follows: let promises = []; for (let i = 0; i < requests.length; i++) { promises.push(axios.get(request[i].url, { params: {...} })); } axios.all(promises).then(/* use the data */); The problem

Axios request giving getter setter methods instead of data queried

99封情书 提交于 2019-11-27 19:32:12
问题 I'm working with Laravel and Vue to make a single page web application. I've used Vue before to get the data from a database using a controller with no problem, but for some reason I'm now only getting a seemingly infinitely nested JS object that has getter and setter methods stored in each parent object instead of the data I queried. I've seen other people with similar issues, but the solutions that worked for them didn't work for me. For example, some people used JSON.parse(JSON.stringify

Unable to catch and log the Error response from an axios request

我怕爱的太早我们不能终老 提交于 2019-11-27 19:03:24
问题 I am having a axios request in my react application, for which I am following the axios npm docs. This is my axios request axios.post(helper.getLoginApi(), data) .then((response) => { console.log(response); this.props.history.push(from.pathname) }) .catch((error)=> { console.log(error); }) I am able to successfully log the data on a successful request. However When I intentionally produce an error and try to console.log it, I don't get the result logged instead, I just see POST http:/