sdy

add request functions

...@@ -3,6 +3,11 @@ const router = express.Router(); ...@@ -3,6 +3,11 @@ const router = express.Router();
3 const AssistantV2 = require("ibm-watson/assistant/v2"); 3 const AssistantV2 = require("ibm-watson/assistant/v2");
4 const { IamAuthenticator } = require("ibm-watson/auth"); 4 const { IamAuthenticator } = require("ibm-watson/auth");
5 5
6 +const request = require('request');
7 +const parser = require('xml2json');
8 +const coronaUrl = "http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19InfStateJson";
9 +const queryParams = '?' + encodeURIComponent('ServiceKey') + '=AZrC9RiqrxwllsI6PMbA9orNqoHCHvmriEKYHfdcpewFnbChIrmKpdehGjBt6fVGDbIAcwS0UVd7Ms5AMX29ig%3D%3D';
10 +
6 const authenticator = new IamAuthenticator({ 11 const authenticator = new IamAuthenticator({
7 apikey: process.env.WATSON_ASSISTANT_APIKEY, 12 apikey: process.env.WATSON_ASSISTANT_APIKEY,
8 }); 13 });
...@@ -44,4 +49,17 @@ router.post("/message", async (req, res) => { ...@@ -44,4 +49,17 @@ router.post("/message", async (req, res) => {
44 } 49 }
45 }); 50 });
46 51
52 +router.get("/corona", async (req, res) => {
53 + await request({
54 + url: coronaUrl + queryParams,
55 + method: 'GET'
56 + }, (err, r, body) => {
57 + // console.log("err : ", err);
58 + // console.log("res : ", res);
59 + // console.log("body : ", body);
60 + const json = parser.toJson(body);
61 + res.send(json);
62 + });
63 +});
64 +
47 module.exports = router; 65 module.exports = router;
......