小编1_1*_*1_1的帖子

Azure(函数)参数在 Python 中声明,但不在 function.json 中声明

我无法理解发生了什么事。我确实遵循所有 Microsoft 文档,实际上甚至不使用我自己的任何脚本/代码。首先,我按照他们的文档创建了 Python 函数。有效。 https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli%2Ccmd%2Cbrowser 使用命令将 Azure Functions 连接到 Azure 存储的第二个文档线工具。不可重现。https://learn.microsoft.com/en-us/azure/azure-functions/functions-add-output-binding-storage-queue-cli?pivots=programming-language-python&tabs=bash%2Cbrowser 我确实遵循每一步,但收到错误。

更令人惊讶的是,他们最终向我展示了与第一篇文章不同的代码。我尝试了两个版本——没有一个有效。

这些是来自他们文档的代码。这是他们的 python 脚本代码 ( init .py )

import logging

import azure.functions as func


def main(req: func.HttpRequest, msg: func.Out[func.QueueMessage]) -> str:

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        msg.set(name)
        return func.HttpResponse(f"Hello {name}!")
    else:
        return func.HttpResponse(
            "Please pass a name on the query string or in the request body",
            status_code=400
        )
Run Code Online (Sandbox Code Playgroud)

这是 JSON 函数代码:

{ …
Run Code Online (Sandbox Code Playgroud)

python azure azure-functions

8
推荐指数
1
解决办法
1万
查看次数

在 Azure Functions (NodeJS) 中处理多个 HTTP 方法的正确方法是什么

在 Azure Functions 中构建应用程序时,您可以指定 function.json 中接受的 HTTP 方法

给定一个可以执行多种功能(GET、PUT POST 等)的 API,创建该功能的最佳方法是什么。

需要提供可用的共享逻辑和库,因此我正在寻找一种可以在单个类中启用所有方法的模式,但不确定如何在 function.json 中定义它,以便每个 HTTP 方法可以有自己的入口点。

另一种选择是创建一个函数,该函数基本上选择该函数的方法和类,但这似乎是一些中间件开销,我确信可以以更好的方式处理。

即我认为我不应该为每个为其创建函数的对象执行此操作,并且必须有更好的模式。

 async HandleRequest(){
        return validateJwt(function(context,req){
            if(req.method === 'GET'){
            }
            else if(req.method === 'POST'){

            }
            else if(req.method === 'DELETE'){

            }
            else if(req.method === 'PUT'){

            }
            else if(req.method === 'PATCH'){

            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

http http-method node.js azure-functions

4
推荐指数
1
解决办法
6746
查看次数

标签 统计

azure-functions ×2

azure ×1

http ×1

http-method ×1

node.js ×1

python ×1