Javascript中的简单Azure功能在队列中使用HTTP触发器主体

问题描述 投票:1回答:1

所以我在MS网站上搞乱了Use Azure Functions to automate SQL DW compute level ......我创建了一个HTTP触发器,它会在命中时向队列发送一个msg。我是Javascript的新手,我想知道如何使用HTTP请求'body'代替我在下面的变量

module.exports = function (context, res,) {
    var timeStamp = new Date().toISOString();
    context.log('JavaScript timer trigger function ran!', timeStamp);   
    context.res = { status: 201, body: "Resuming Datawarehouse" };        var operation = {
        "operationType": "ResumeDw"
    }
    context.bindings.operationRequest = operation;
    context.done(null, res);
};

很简单,我想在我的HTTP请求体中有一些JSON会触发这个触发器,然后我想只使用那个体内的队列。在上面的这种情况下,它将取代var operation =

请问有什么想法吗?

仅仅是一个FYI,我希望它取代我已有的东西:

    var operation = {
        "operationType": "ResumeDw"
    }
    context.bindings.operationRequest = operation;

这在Function中是静态的,但是我希望HTTP请求发送的任何内容都可以发送到我的队列。

javascript azure azure-functions
1个回答
1
投票

你的函数的第二个参数是req,而不是res,它允许你访问HTTP请求,包括它的正文:

module.exports = function(context, req) {
    // req.body is a thing
    var operation = {
        "operationType": req.body.operationType
    };
    context.bindings.operationRequest = operation;
    context.res = { status: 201, body: "Resuming Datawarehouse" };
    context.done();
};
© www.soinside.com 2019 - 2024. All rights reserved.