sdy

add request functions

......@@ -3,6 +3,11 @@ const router = express.Router();
const AssistantV2 = require("ibm-watson/assistant/v2");
const { IamAuthenticator } = require("ibm-watson/auth");
const request = require('request');
const parser = require('xml2json');
const coronaUrl = "http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson";
const queryParams = '?' + encodeURIComponent('ServiceKey') + '=AZrC9RiqrxwllsI6PMbA9orNqoHCHvmriEKYHfdcpewFnbChIrmKpdehGjBt6fVGDbIAcwS0UVd7Ms5AMX29ig%3D%3D';
const authenticator = new IamAuthenticator({
apikey: process.env.WATSON_ASSISTANT_APIKEY,
});
......@@ -44,4 +49,17 @@ router.post("/message", async (req, res) => {
}
});
router.get("/corona", async (req, res) => {
await request({
url: coronaUrl + queryParams,
method: 'GET'
}, (err, r, body) => {
// console.log("err : ", err);
// console.log("res : ", res);
// console.log("body : ", body);
const json = parser.toJson(body);
res.send(json);
});
});
module.exports = router;
......