【发布时间】:2018-01-28 18:42:45
【问题描述】:
我正在尝试使用 Cosmos DB 输入绑定运行 http 触发 Azure 函数。我希望 http 触发器的 url 在查询字符串中包含几个参数,这些参数绑定到输入 Cosmos DB 绑定的 SQL 查询。我正在function.json 中尝试以下绑定,但它不起作用(该函数甚至没有被触发):
{
"direction": "in",
"type": "httpTrigger",
"authLevel": "anonymous",
"name": "req",
"methods": [ "get" ],
"route": "users/{age=age?}/{gender=gender?}"
},
{
"direction": "in",
"type": "documentDB",
"name": "users",
"databaseName": "Database",
"collectionName": "Users",
"sqlQuery": "SELECT * FROM x where x.age = {age} and x.gender = {gender}",
"connection": "COSMOSDB_CONNECTION_STRING"
},
根据answer,路由约束users/{age=age?}/{gender=gender?} 对Web API 有效,并且根据documentation您可以使用任何Web API 路由约束与您的参数。最终,我想向 Azure 函数发出一个类似于 api/users?age=30&gender=male 的 GET 请求。那应该怎么做呢?
【问题讨论】:
标签: azure azure-functions azure-cosmosdb azure-functions-runtime