Toggle navigation
Toggle navigation
This project
Loading...
Sign in
term-project
/
project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Solhee
2020-11-30 23:52:51 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
d1461ef890b6164516228d83232ce0cb14238b8d
d1461ef8
2 parents
899dda72
b5879ce7
Merge branch 'api' of
http://khuhub.khu.ac.kr/term-project/project
into master
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
26 deletions
express/foodapi.js
express/foodapi.js
View file @
d1461ef
let
request
=
require
(
'request'
);
var
express
=
require
(
'express'
);
var
request
=
require
(
'request'
);
//
REST API 경로 & 요청 메시지
const
url
=
'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList?ServiceKey='
;
//
xml을 json으로 바꾼다.
const
convert
=
require
(
'xml-js'
)
;
//api key
const
key
=
'ofY2ppOq5kBqT5jYPaGsW%2BEy7OR5a1bf5Z9PHvqNKvwO5DSCaU2x2qCj%2FoXnuB1YVbMTlErkHWSMEsR5b7isrw%3D%3D'
;
var
url
=
'http://apis.data.go.kr/1470000/FoodAdtvInfoService/getFoodAdtvInfoList'
;
var
key
=
'ofY2ppOq5kBqT5jYPaGsW%2BEy7OR5a1bf5Z9PHvqNKvwO5DSCaU2x2qCj%2FoXnuB1YVbMTlErkHWSMEsR5b7isrw%3D%3D'
;
var
queryParams
=
'?'
+
encodeURIComponent
(
'ServiceKey'
)
+
'='
+
key
;
//queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000');
//queryParams += '&' + encodeURIComponent('pc_kor_nm') + '=' + encodeURIComponent('과.채음료');
//queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('3');
queryParams
+=
'&'
+
encodeURIComponent
(
'numOfRows'
)
+
'='
+
encodeURIComponent
(
'100'
);
//REST(URL)
const
complete_url
=
url
+
key
;
// '&numOfRows=2&pageNo=2';
global
.
foods
=
new
Array
();
console
.
log
(
complete_url
);
request
(
complete_url
,
function
(
error
,
response
,
body
){
if
(
!
error
&&
response
.
statusCode
==
200
)
console
.
log
(
body
);
})
/*
queryParams += '&' + encodeURIComponent('prdlst_cd') + '=' + encodeURIComponent('C0118010300000');
queryParams += '&' + encodeURIComponent('pc_kor_nm') + '=' + encodeURIComponent('과.채음료');
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1');
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('3');
*/
/*
예제코드
request
({
url
:
url
+
queryParams
,
method
:
'GET'
},
function
(
error
,
response
,
body
)
{
if
(
error
){
console
.
log
(
'에러입니다.'
)
}
else
{
if
(
response
.
statusCode
==
200
)
var
result
=
body
;
var
xmltojson
=
convert
.
xml2json
(
result
,{
compact
:
true
,
spaces
:
4
});
//console.log(xmltojson);
var
resObj
=
eval
(
"("
+
xmltojson
+
")"
);
for
(
var
i
=
0
;
i
<
100
;
i
++
){
function
fo
(){
foods
.
push
(
food
);
}
function
foo
(){
var
food
=
resObj
.
response
.
body
.
items
.
item
[
i
].
PC_KOR_NM
.
_text
;
fo
();
}
var
food
=
resObj
.
response
.
body
.
items
.
item
[
i
].
PC_KOR_NM
.
_text
;
global
.
foods
.
push
(
food
);
//foods.food = resObj.response.body.items.item[i].PC_KOR_NM._text;
//foods.push(resObj.response.body.items.item[i].PC_KOR_NM._text);
//console.log(resObj.response.body.items.item[i].PC_KOR_NM._text);
}
//console.log(xmltojson);
}
//console.log('Status', response.statusCode);
//console.log('Headers', JSON.stringify(response.headers));
//console.log('Reponse received', body);
console
.
log
(
foods
[
99
]);
});
*/
// module.exports.이름 = 함수
;
console
.
log
(
foods
)
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment