Node.js 如何使用简单的HttpGET CRUD NodeJS示例?
假设我只使用生成的默认模板:Node.js 如何使用简单的HttpGET CRUD NodeJS示例?,node.js,azure-functions,Node.js,Azure Functions,假设我只使用生成的默认模板: module.exports = function (context, req, intable) { context.log("Retrieved records:", intable); context.res = { status: 200, body: intable }; context.done(); }; 以及以下json文件: { "bindings": [ {
module.exports = function (context, req, intable) {
context.log("Retrieved records:", intable);
context.res = {
status: 200,
body: intable
};
context.done();
};
以及以下json文件:
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"authLevel": "function"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "table",
"name": "inTable",
"tableName": "person",
"connection": "serverlessexamplestorage_STORAGE",
"direction": "in",
"take": "100"
}
],
"disabled": false
}
如何才能成功调用该函数
门户网站的“运行”按钮通过向您的职能部门发送POST请求来工作。但是,该模板指定方法:[“get”]
将函数限制为仅支持get请求(因此出现405“Method not allowed”错误)
您可以使用类似客户机或您最喜欢的客户机发送GET请求,该函数将成功运行。或者,您也可以通过向方法数组(方法:[“get”,“POST”]
)添加“POST”来允许函数接受POST请求,并且您可以从门户调用它
我同意这有点令人困惑。问题是Functions portal不是一个完整的HTTP客户机,因此它不允许您指定HTTP方法、头等。我们的repo中有一个改进方法。我们将在门户中构建一个功能齐全的HTTP客户端的程度待定,因此目前您最好的选择是在所有情况下使用外部客户端,但简单的情况除外。这是有道理的。我也在使用Postman,但是当我使用POST运行HttpPost示例时,我忘了更改下拉列表以获取。这是一个单独的问题,是否有一种方法可以动态修改
json
config文件,以便在inTable
填充之前更改TableName
?