mirror of
https://github.com/Raghu-Ch/ReactWeather.git
synced 2026-02-10 11:03:02 -05:00
Initial commit React Weather App
This commit is contained in:
20
app/api/openWeatherMap.jsx
Normal file
20
app/api/openWeatherMap.jsx
Normal file
@@ -0,0 +1,20 @@
|
||||
var axios = require('axios');
|
||||
|
||||
const OPEN_WEATHER_MAP_URL = 'http://api.openweathermap.org/data/2.5/weather?appid=37916edc2b2b7a2f53fa8965e5d53db6&units=imperial';
|
||||
|
||||
module.exports = {
|
||||
getTemp: function (location) {
|
||||
var encodedLocation = encodeURIComponent(location);
|
||||
var requestUrl = `${OPEN_WEATHER_MAP_URL}&q=${encodedLocation}`;
|
||||
|
||||
return axios.get(requestUrl).then(function (res) {
|
||||
if (res.data.cod && res.data.message) {
|
||||
throw new Error(res.data.message);
|
||||
} else {
|
||||
return res.data.main.temp;
|
||||
}
|
||||
}, function(err) {
|
||||
throw new Error(err.response.data.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user