Last active
September 16, 2020 14:55
-
-
Save jinwook-k/810623510e54dce59d8f400672b8112b to your computer and use it in GitHub Desktop.
server/api/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// POST Request - dynamically get the weather data based on request body | |
router.post("/weather", async (req, res) => { | |
... | |
}); | |
// POST Request - get the weather data from the api, save it to mongo, then return the data back | |
router.post("/weatherMongo", async(req, res) => { | |
const {zipCode, tempMetric} = req.body; | |
let weather = new Weather(); | |
let weatherData = await weather.getWeatherData(zipCode, tempMetric); | |
await weather.saveWeatherDataToMongo(zipCode, weatherData); | |
res.header("Content-Type",'application/json'); | |
res.send(JSON.stringify(weatherData, null, 4)); | |
}) | |
// GET Request - get the weather data saved from Mongo | |
router.get("/weatherMongo", async(req, res) => { | |
const {zipCode} = req.query; | |
let weather = new Weather(); | |
let weatherData = await weather.getWeatherDataFromMongo(zipCode); | |
res.header("Content-Type",'application/json'); | |
res.send(JSON.stringify(weatherData, null, 4)); | |
}) | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment