엄지월드

node를 이용한 API 호출 시 body 값 설정 방법 본문

Node.js

node를 이용한 API 호출 시 body 값 설정 방법

킨글 2019. 9. 7. 10:46
반응형
app.get('/license', (req, res) => {
    const url = 'https://api.co.kr/api/getLicenseList';
    var formData = {
        COMPANY_AUTHORITY_KEY: 'key value',
        API_SERVICE_KEY: 'key value',
    };
    const options = {
        uri: url, 
        formData: formData, 
        method: 'POST' // POST 형식으로 전달.
    }
    request(options, (err, response, body) => {
        console.log('Request complete');
        if (err) console.log('Request err: ', err);
        // console.log(body);
        var rData = JSON.parse(body); // return 받은 data를 JSON 형식으로 rData에 저장.

        res.render('licenseAPIJsonRead.ejs', {rData}); // view page
    });
   
});

 

 

도움이 되셨다면 광고 한번씩 클릭 부탁드립니다 😁

 

'Node.js' 카테고리의 다른 글

node 다른 파일 코드 참조  (0) 2020.01.19
node를 이용한 excel 파일 생성 예제  (0) 2019.09.12
ejs 활용 json 읽기  (0) 2019.09.04
node Session 구현  (0) 2019.06.28
Cannot find module 'html'  (0) 2019.02.27
Comments