박주영

Delete foodapi_rawmaterial.js

1 -// 식품의약품 안전처 품목제조보고(원재료) API 요청 예시입니다
2 -
3 -var express = require('express');
4 -var request = require('request');
5 -
6 -var url ='http://openapi.foodsafetykorea.go.kr/api';
7 -var key ='f8ce3271a2dc4decb83b';
8 -var filetype ='json';
9 -var startIndex = 1;
10 -var endIndex = 5;
11 -var NameOfProduct ='하루견과 요거트S'; // 제품명 넣는 자리
12 -
13 -var queryParams = '/' + encodeURIComponent(key);
14 -queryParams += '/' + encodeURIComponent('C002');
15 -queryParams += '/' + encodeURIComponent(filetype);
16 -queryParams += '/' + encodeURIComponent(startIndex);
17 -queryParams += '/' + encodeURIComponent(endIndex);
18 -queryParams += '/' + encodeURIComponent('PRDLST_NM') + '=' + encodeURIComponent(NameOfProduct);
19 -
20 -//var fullRequest = encodeURIComponent("http://openapi.foodsafetykorea.go.kr/api/f8ce3271a2dc4decb83b/C002/xml/1/5/PRDLST_REPORT_NO=200101260032");
21 -//var fullRequest ='http://openapi.foodsafetykorea.go.kr/api/f8ce3271a2dc4decb83b/C002/json/1/5';
22 -
23 -console.log("[Input msg] ", NameOfProduct);
24 -
25 -request({
26 - url: url + queryParams,
27 - //url : fullRequest,
28 - method: 'GET'
29 -}, function (error, response, body) {
30 - if(error){
31 - console.log('에러입니다.')
32 - }
33 - else{
34 - if(response.statusCode ==200){
35 - console.log("식품명으로 식품유형과 첨가물 정보를 받아옵니다...");
36 - var result =body;
37 - var resObj = eval("("+result+")");
38 - var ProductCategory = resObj.C002.row[0].PRDLST_DCNM;
39 - // 첨가물정보 API가 입력으로 받을 parameter
40 -
41 - //console.log(result);
42 - console.log("[처리결과] ",resObj.C002.RESULT.MSG);
43 - console.log("[유형] ", ProductCategory);
44 - console.log("[첨가물] ",resObj.C002.row[0].RAWMTRL_NM )
45 - }
46 - }
47 -
48 -});