Solhee

foodapi_rawmaterial

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 ='인증키'; // 12월03일 신청하였습니다.
8 +var filetype = 'json';
9 +var startIndex = 1;
10 +var endIndex = 5;
11 +var NameOfProduct = '해오름다시마간장'; // 제품명 넣는 자리
12 +
13 +var queryParams = '/' + key;
14 +queryParams += '/' + encodeURIComponent('C002');
15 +queryParams += '/' + encodeURIComponent(filetype);
16 +queryParams += '/' + encodeURIComponent('startIdx') + '=' + encodeURIComponent(startIndex);
17 +queryParams += '/' + encodeURIComponent('endIdx') + '=' + encodeURIComponent(endIndex);
18 +queryParams += '&' + encodeURIComponent('PRDLST_NM') + '=' + encodeURIComponent('제품명');
19 +
20 +
21 +
22 +request({
23 + url: url + queryParams,
24 + method: 'GET'
25 +}, function (error, response, body) {
26 + if(error){
27 + console.log('에러입니다.')
28 + }
29 + else{
30 + if(response.statusCode ==200){
31 + var result =body;
32 +
33 + var resObj = eval("("+result+")");
34 +
35 + console.log(result);
36 +
37 +
38 + }
39 + }
40 +
41 +});