节点 Azure 函数中的附加参数
Additional Parameter in Node Azure Function
我刚刚开始学习使用 NodeJS 实现 Azure Functions,我正在尝试向触发函数添加额外的自定义参数
因为这是 Microsoft 推荐的输入绑定方式,但我无法让它工作。
我收到 404 未找到错误。
当我从 function.json 中删除 id 对象时,该函数有效,但 id 未定义。
我尝试使用 get 和 id 作为查询参数调用函数,并在正文中使用 { id: 123 } 作为 post 调用函数,但没有成功。
有人能帮忙吗?
提前致谢。
index.ts
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest,
id: string
): Promise<void> {
context.log("HTTP trigger function processed a request with id.", id);
context.res = {
body: {
id,
},
contentType: "application/json",
};
};
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "id",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/respository/index.js"
}
在 Node js
Azure 函数 中,我们没有 Attributes和 Annotations 所以我们不能在 azure 函数中添加额外的参数。 JavaScript
不支持属性。
在 Azure 函数 C# class libraries 和 Java 中,HttpTrigger
属性可用于配置函数。
您可以在属性构造函数参数、webhook 类型和路由模板中设置授权级别和允许的 HTTP 方法。有关这些设置的详细信息,请参阅 configuration。
参考here
我刚刚开始学习使用 NodeJS 实现 Azure Functions,我正在尝试向触发函数添加额外的自定义参数 因为这是 Microsoft 推荐的输入绑定方式,但我无法让它工作。
我收到 404 未找到错误。 当我从 function.json 中删除 id 对象时,该函数有效,但 id 未定义。
我尝试使用 get 和 id 作为查询参数调用函数,并在正文中使用 { id: 123 } 作为 post 调用函数,但没有成功。
有人能帮忙吗?
提前致谢。
index.ts
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest,
id: string
): Promise<void> {
context.log("HTTP trigger function processed a request with id.", id);
context.res = {
body: {
id,
},
contentType: "application/json",
};
};
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "id",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/respository/index.js"
}
在 Node js
Azure 函数 中,我们没有 Attributes和 Annotations 所以我们不能在 azure 函数中添加额外的参数。 JavaScript
不支持属性。
在 Azure 函数 C# class libraries 和 Java 中,HttpTrigger
属性可用于配置函数。
您可以在属性构造函数参数、webhook 类型和路由模板中设置授权级别和允许的 HTTP 方法。有关这些设置的详细信息,请参阅 configuration。
参考here