https://docs.microsoft.com/ja-jp/learn/modules/create-serverless-logic-with-azure-functions/
MicrosoftLearnをやってみました。これめちゃ便利ですね。






curlでのテスト
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を更新する
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する
{
"readings": [
{
"driveGearId": 1,
"timestamp": 1534263995,
"temperature": 23
},
{
"driveGearId": 3,
"timestamp": 1534264048,
"temperature": 45
},
{
"driveGearId": 18,
"timestamp": 1534264050,
"temperature": 55
}
]
}


モニタータブで呼び出し成功していることを確認

