Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FromQuery support in Azure Functions v3

I am trying to use [FromQuery] with Azure Function v3 but I am getting the following error:

Cannot bind parameter 'search' to type String.

For the following method:

[FunctionName("GetObjects")]
public ActionResult<IActionResult> QueryObjects(
    [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "objects")]
    HttpRequest req,
    ILogger log,
    [FromQuery] string search = null)
{
    //do some stuff
}

Is [FromQuery] not supported?

Should I use req.Query["search"] to get the query parameter?

From functions.desp.json

Related to binding

"Microsoft.Extensions.Configuration.Binder/3.1.1": {
    "dependencies": {
        "Microsoft.Extensions.Configuration": "3.1.2"
    },
    "runtime": {
        "lib/netcoreapp3.1/Microsoft.Extensions.Configuration.Binder.dll": {
        "assemblyVersion": "3.1.1.0",
        "fileVersion": "3.100.119.61404"
        }
    }
},

like image 288
doorman Avatar asked Mar 03 '20 17:03

doorman


People also ask

What are the types of bindings supported by Azure functions?

Binding to a function is a way of declaratively connecting another resource to the function; bindings may be connected as input bindings, output bindings, or both. Data from bindings is provided to the function as parameters. You can mix and match different bindings to suit your needs.

What is HTTP trigger in Azure function?

The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is: HTTP 204 No Content with an empty body in Functions 2.

How do you read a cosmos DB from Azure function?

The Azure Cosmos DB input binding uses the SQL API to retrieve one or more Azure Cosmos DB documents and passes them to the input parameter of the function. The document ID or query parameters can be determined based on the trigger that invokes the function.

How do I provide a routing function in Azure?

To pass value in the function route in Azure function, we would have to modify the route parameter as “Hello/{valueName}”. Then add a parameter with the same name as the valueName in the Run method to use this value in your azure function. But adding {valueName} makes it a mandatory value to be passed.


1 Answers

This is what you face now:

enter image description here

Method signatures developed by the azure function C # class library can include these:

ILogger or TraceWriter for logging (v1 version only)

A CancellationToken parameter for graceful shutdown

Mark input and output bindings by using attribute decoration

Binding expressions parameters to get trigger metadata

From this doc, it seems that it is not supported. You can create your custom binding like this, and dont forget to register it in the startup.

like image 138
Cindy Pau Avatar answered Oct 03 '22 04:10

Cindy Pau