Azure Functions: How to Bind HTTP Trigger Function Query String Parameters with Cosmos DB SQL Query

I am trying to run the Azure trigger function with Cosmos DB input binding. I would like the http trigger URL to include several parameters in the query string that are bound to the Cosmos database binding SQL query. I try to use the following bindings in function.json, but it does not work (the function does not even start):

{
  "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"
},

According to this answer, the route restriction is users/{age=age?}/{gender=gender?}valid for the web API and, in accordance with, you can use any web API route restriction with your parameters. Ultimately, I would like to make a GET request for an Azure function that looks like api/users?age=30&gender=male. How to do it?

+4
1

, Cosmos , , . ?age=30. , .

, .

users/{age}/{gender}, Cosmos SqlQuery GET http://yourfunctionhost/yourfunction/users/30/male

+4

Source: https://habr.com/ru/post/1684065/


All Articles