如何使用简单的HttpGET-CRUD-NodeJS例子?

鉴于我只是使用生成的默认模板:

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 } 

我怎么做才能成功地调用函数?

在这里输入图像说明

门户“运行”button通过发送POST请求到您的function。 但是,该模板指定methods: [ "get" ]限制函数只支持GET请求(因此405“方法不允许”错误)。

您可以使用Postman这样的客户端,或者任何您喜欢的客户端发送GET请求,并且该函数将成功运行。 另外,你也可以通过在方法数组中添加“post”( methods: [ "get", "post" ] )来允许函数接受POST请求,你可以从门户中调用它。

我同意这有点混乱。 问题是函数门户不是一个完整的HTTP客户端,所以它不允许你指定http方法,头文件等。在我们的回购中有一个公开的问题来改进它。 我们要在门户网站中build立一个全function的HTTP客户端程度是TBD,所以现在最好的select是使用一个外部客户端来处理所有的情况。