Toggle navigation
Toggle navigation
This project
Loading...
Sign in
윤창신
/
searchGuide
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
김서영
2019-11-22 21:05:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
693814f7c628ef2a3f606b117752a7f6d051c728
693814f7
1 parent
94198315
add apiReques.js/ request ETRI API and reslove response body
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
api/apiRequest.js
api/apiRequest.js
0 → 100644
View file @
693814f
require
(
'dotenv'
).
config
();
const
rp
=
require
(
"request-promise"
);
// Api URL
const
URL
=
{
"ETRI"
:
"http://aiopen.etri.re.kr:8000/"
,
}
// ETRI Api Request Format
const
apiRequestJsonFrame
=
{
"request_id"
:
"reserved field"
,
"access_key"
:
process
.
env
.
ETRI_API_KEY
,
"argument"
:
{}
};
let
apiRequest
=
{};
/**
* @param {String} query 세부 url / 형식은 api사이트 참조
* @param {Object} argument 필요한 argument / 형식은 api사이트 참조
* @returns {Object} api사이트에서 정해진 형식의 응답을 받아옵니다.
* @description 이 함수는 이미 정해진 url(etri api)+query의
경로로 argument와 함께 request를 보냅니다.
그 후 얻은 응답을 js object로 보내줍니다.
*/
apiRequest
.
ETRI
=
async
(
query
,
argument
)
=>
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
let
apiReqJson
=
apiRequestJsonFrame
;
apiReqJson
.
argument
=
argument
;
let
apiReqOption
=
{
uri
:
URL
.
ETRI
+
query
,
body
:
JSON
.
stringify
(
apiReqJson
)
};
rp
.
post
(
apiReqOption
)
.
then
(
(
body
)
=>
{
body
=
JSON
.
parse
(
body
);
resolve
(
body
);
})
})
}
module
.
exports
=
apiRequest
;
Please
register
or
login
to post a comment