Azure およびNode.js ともに初心者です
使用環境
使用環境:Azure Functions
使用言語: Node.js
質問
Azure Functions からNode.jsのhttpモジュールを使用してAPIをcallするアプリを作成しています。
Qiitaのサンプル記事をもとに郵便番号検索APIをcallし、レスポンス値を加工する処理を作成しようとしましたが、
想定通りにhttpリクエストが実行されず困っています。
AzureとNode.jsのどちらも知識があまりなく、問題の切り分けができず。
AzureかNode.jsで確認すべき点や修正したほうがいい箇所がありましたら、ご指摘いただける助かります。
html
1const https = require('https'); 2const url = `https://zipcloud.ibsnet.co.jp/api/search?zipcode=7830060`; 3 const options = { 4 method: 'GET', 5 } 6 }; 7const client = https.request(url, options, (res) => { 8 context.log(res.statusCode); 9 context.log(res.headers); 10 let resBody = ''; 11 res.on('data', (chunk) => { resBody += chunk; }); 12 res.on('end', () => { 13 context.log(resBody); 14 context.res = {status: 204}; 15 context.done(); 16 }); 17 }); 18 client.on('error', (e) => { 19 context.log.error(e); 20 context.res = {status: 500}; 21 context.done(); 22 }); 23 client.end(); 24};
試したこと
①httpリクエスト処理の戻り値の変数をcontext.log()で表示
「request.undefined」が返ってくることを確認
②Azure FunctionsのKuduの実行ログを確認
Client Requestから始まる長い戻り値?が返ってきていることは確認しています。
確認点がわからず苦戦しています。
html
12022-07-ddThh:mm:ss.999 [Information] Client Request{ 2_events:[object: null prottype]{ 3 response:[Function:bound onceWrapper] 4--以下略--
コードサンプル
https://qiita.com/ma2shita/items/a9844a3a8e618600a109
###使用しているAPI
http://zipcloud.ibsnet.co.jp/doc/api
回答2件
あなたの回答
tips
プレビュー