使用带有触发器http的Azure功能,使用基于http请求的ID输入DocumentDB

时间:2017-06-27 12:59:33

标签: azure azure-functions

所以我从this page读到的是,我应该能够:

  1. 触发HTTP
  2. 输入Http请求
  3. 输入DocumentDb
  4. 输出DocumentDb
  5. 数字1,2和4正在运作。但是如何使用路径中的ID从DocumentDB获取文档?

    我可以在DocumentDb输入中使用代理路由中的{path}吗?

    我有一个像这样定义的代理。

    {
        "$schema": "http://json.schemastore.org/proxies",
        "proxies": {
            "index": {
                "matchCondition": {
                    "route": "{*path}",
                    "methods": [
                        "GET"
                    ]
                },
                "backendUri": "https://%WEBSITE_SITE_NAME%.azurewebsites.net/api/Index"
            },
            "api": {
                "matchCondition": {
                    "route": "api/{*path}"
                },
                "backendUri": "https://%WEBSITE_SITE_NAME%.azurewebsites.net/api/{path}"
            },
            "index existing subscription": {
                "matchCondition": {
                    "route": "/subscription/{*path}",
                    "methods": [
                        "GET"
                    ]
                },
                "backendUri": "https://%WEBSITE_SITE_NAME%.azurewebsites.net/api/IndexSubscription/{path}"
            }
        }
    }
    

1 个答案:

答案 0 :(得分:0)

以下是带有文档数据库输入绑定的函数示例。

function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "route": "MyDocFunc/{docid}"
    },
    {
      "type": "documentDB",
      "name": "inputDocument",
      "databaseName": "MyDocDB",
      "collectionName": "MyCollection",
      "id": "{docid}",
      "connection": "mydocdb_DOCUMENTDB",
      "direction": "in"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}

csx

public static async Task<HttpResponseMessage> Run(
    HttpRequestMessage req, string docid, string inputDocument)
{
    return req.CreateResponse(HttpStatusCode.OK, inputDocument);
}

代理的使用不会对此产生太大影响......您可以将代理参数传递给函数参数。