diff --git a/package-lock.json b/package-lock.json index 9a7e686..df2e92d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1715,6 +1715,15 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, + "axios": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz", + "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", + "requires": { + "follow-redirects": "^1.3.0", + "is-buffer": "^1.1.5" + } + }, "axobject-query": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.0.2.tgz", diff --git a/package.json b/package.json index 95c7a0f..b8a6b5f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "axios": "^0.18.0", "normalize": "^0.3.1", "normalize.css": "^8.0.1", "react": "^16.7.0", diff --git a/src/App.js b/src/App.js index d268d9d..78d4a4a 100755 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import 'normalize.css'; import './App.css'; +import api from './utils/api'; import PropTypes from 'prop-types'; class LocationInput extends Component { @@ -73,12 +74,13 @@ class App extends Component { } handleSubmit(location) { console.log('location: ' + location); + + api.fetchCurrentWeather(location); // this.setState(_ => { // // }); } - render() { return (
diff --git a/src/utils/api.js b/src/utils/api.js new file mode 100644 index 0000000..d15ab45 --- /dev/null +++ b/src/utils/api.js @@ -0,0 +1,15 @@ +var axios = require('axios'); + +var apikey = "8fad34166684286360dc6d77073bd5e5"; +var params = "&APPID=" + apikey; + +module.exports = { + fetchCurrentWeather: function(location) { + var link = window.encodeURI("http://api.openweathermap.org/data/2.5/weather?q=" + location + params); + return axios.get(link) + .then(function(results) { + console.log('results: ' + results); + console.log(JSON.stringify(results)); + }); + } +}