https://docs.microsoft.com/ja-jp/learn/modules/create-serverless-logic-with-azure-functions/
MicrosoftLearnをやってみました。これめちゃ便利ですね。
curlでのテスト
1 2 3 |
yuta@DESKTOP-V36210S:/mnt/c$ curl -X POST -H "Content-Type: application/json" -d '{"name":"Azure"}' https://escalator-functions-0910.azurewebsites.net/api/HttpTrigger1?code=81yzkMKApPA4AvZwRvWvwS9B0WMFANwdaODJhieNZH4Ca2/IZk4eHQ== Hello Azureyuta@DESKTOP-V36210S:/mnt/c$ yuta@DESKTOP-V36210S:/mnt/c$ |
index.jsを更新する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
module.exports = function (context, req) { context.log('Drive Gear Temperature Service triggered'); if (req.body && req.body.readings) { req.body.readings.forEach(function(reading) { if(reading.temperature<=25) { reading.status = 'OK'; } else if (reading.temperature<=50) { reading.status = 'CAUTION'; } else { reading.status = 'DANGER' } context.log('Reading is ' + reading.status); }); context.res = { // status: 200, /* Defaults to 200 */ body: { "readings": req.body.readings } }; } else { context.res = { status: 400, body: "Please send an array of readings in the request body" }; } context.done(); }; |
次のBodyでPOSTする
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ "readings": [ { "driveGearId": 1, "timestamp": 1534263995, "temperature": 23 }, { "driveGearId": 3, "timestamp": 1534264048, "temperature": 45 }, { "driveGearId": 18, "timestamp": 1534264050, "temperature": 55 } ] } |
モニタータブで呼び出し成功していることを確認