1// Simple GET request using fetch
2fetch('https://api.npms.io/v2/search?q=react')
3 .then(response => response.json())
4 .then(data => this.setState({ data: data.feed }));
1/* React get method. */
2
3componentWillMount(){
4 fetch('/getcurrencylist',
5 {
6 /*
7 headers: {
8 'Content-Type': 'application/json',
9 'Accept':'application/json'
10 },
11 */
12 method: "get",
13 dataType: 'json',
14 })
15 .then((res) => res.json())
16 .then((data) => {
17 var currencyList = [];
18 for(var i=0; i< data.length; i++){
19 var currency = data[i];
20 currencyList.push(currency);
21 }
22 console.log(currencyList);
23 this.setState({currencyList})
24 console.log(this.state.currencyList);
25 })
26 .catch(err => console.log(err))
27 }