axios

Multiple fetch data axios with React Hooks

微笑、不失礼 提交于 2019-12-11 06:49:25
问题 I would like to get global information from Github user and his repos(and get pinned repos will be awesome). I try to make it with async await but It's is correct? I've got 4 times reRender (4 times console log). It is possible to wait all component to reRender when all data is fetched? function App() { const [data, setData] = useState(null); const [repos, setRepos] = useState(null); useEffect(() => { const fetchData = async () => { const respGlobal = await axios(`https://api.github.com/users

How do you make axios GET request wait?

旧巷老猫 提交于 2019-12-11 06:46:01
问题 Hi I'm having a problem with using axios / fetch GET with a URL that has a parameter that iterates through an array loop for its values axios / fetch doesn't follow the order of the array and just returns whichever response comes first. How would I fix this? const fetch = require("node-fetch"); algo = "eth" // algorithm for wtt hashrate = ['250', '100', '50'] console.log(hashrate) for (var i = 0; i < vhr.length; i++){ var wttURL = "https://whattomine.com/coins.json?" + algo + "=true" + "

CORS header ‘Access-Control-Allow-Origin’ missing from Wikipedia API response [duplicate]

浪子不回头ぞ 提交于 2019-12-11 06:39:23
问题 This question already has an answer here : Does Wikipedia API support CORS or only JSONP available? (1 answer) Closed last year . I'm trying to fetch data from the Wikipedia API with axios in reactJS. This is my get request axios.get('https://en.wikipedia.org/w/api.php?action=opensearch&search=lol&format=json&callback=?') .then((response) => { console.log(response); }) .catch((error)=>{ console.log(error); }); I got this error: Cross-Origin Request Blocked: The Same Origin Policy disallows

What is the best way to structure api config file in react project?

眉间皱痕 提交于 2019-12-11 06:39:01
问题 I am developing react app and for api call i am using axios library. For all api calls i have app.js file, and then when some component needs to make api call just call function from that file. In short that would be little structre for now. In app.js file i have multiple api calls in which i am also seanding header config cause of token authorization. So i want to have a separate config file which will have default api header and all urls i am using for api call. I am looking for a best way

how to display the errors in .catch coming from an api on frontend

纵然是瞬间 提交于 2019-12-11 06:35:37
问题 I am building a project using laravel which is simple api i have built using passport and on the frontend i am using react everything works fine except that i can't catch the error messages in the .catch function i can see the errors in the network tab of my browser but i cant figure out how to display them. here is my UserController class UserController extends Controller { public function create(Request $request) { $data = $request->only('name', 'email', 'password'); $validator = Validator:

Sending requests to Elasticsearch with axios

送分小仙女□ 提交于 2019-12-11 06:27:56
问题 I'm working on a react app which needs to fetch data from elsaticsearch. In frontend, actually I'm trying to use axios to do the request: const query = { query: { match: { "_id": "AV12n5KzsohD5gXzTnOr" } } }; axios.get('http://localhost:9200/my-index/my-type/_search', query) .then((res) => { console.log(res); }); I want to get the specific document with some ID. The above query actually works inside kibana. However, the above query returns all the documents inside my-type, what am I doing

How do you access Axios response with Express?

坚强是说给别人听的谎言 提交于 2019-12-11 06:19:40
问题 I just started working with Express and am currently lost on how to make an Axios request using route parameters and change some locals based on what the request returns. This is what I have so far: helpers.js const axios = require('axios'); const { titleSuffix, organizationPath, varietyPath } = require('./constants'); let organizationData = {}; let varietyData = {}; const Helpers = { fetchOrganization: (organizationID) => { axios.get(organizationPath + organizationID) .then( (response) => {

axios: stop automatic sorting of objects based on keys

你离开我真会死。 提交于 2019-12-11 06:17:59
问题 I am gettting an api response using axios. I am sending the api response sorted w.r.t name http://localhost:8000/api/ingredients/ordering=name The actual object sent is as below from my server. { 2:{"id":2,"name":"anil"}, 1:{"id":1,"name":"sant"}, 3:{"id":3,"name":"vino"} } or pass the key as string instead of integer { "2":{"id":2,"name":"anil"}, "1":{"id":1,"name":"sant"}, "3":{"id":3,"name":"vino"} } or key as alphanumeric { "a2":{"id":2,"name":"anil"}, "a1":{"id":1,"name":"sant"}, "a3":{

Throwing error while downloading file in ASP.NET Core with status code 400

狂风中的少年 提交于 2019-12-11 06:13:53
问题 I'm working on download feature. When I run code on localhost, it runs perfectly without any error. But when I uploads same code to server then it returns Failed to load resource: the server responded with a status of 400 (Bad Request) error in console of browser. For requesting and getting response from server, I have used Axios. I'm newbie to ASP.NET Core + ReactJS technology stack and working on APIs for the first time so it's being difficult for me to figuring out root cause of this error

React.js: Axois Post stay on pending(but i am getting data)

守給你的承諾、 提交于 2019-12-11 06:09:47
问题 I am using axios to perform post request to Node.js. The data does arrive the backend and I can perform some action with it. However, in the network, it always stay pending. Example routers are following: handleSubmit(e){ e.preventDefault(); var added = this.getAddedItems() console.log("added is", added) if(added.length > 0){ for(let i of added){ console.log(i) } axios({ method: 'post', url: '/add', data: added}) } } handleDelete(e,desc){ e.preventDefault() axios({method: "post", url: "