doorman
doorman

Reputation: 16959

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

Upvotes: 5

Views: 3516

Answers (2)

George Chen
George Chen

Reputation: 14334

If you want to bind it directly, it's not possible. So you could try to change your route like Function1/name={name}&research={research} then bind it to string parameter.

Below is my test code:

[FunctionName("Function1")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route="Function1/name={name}&research={research}")] HttpRequest req,
    String name,
    String research,
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    log.LogInformation(research);
    
    string responseMessage = $"Hello, {name}. This HTTP triggered function executed successfully.";

    return new OkObjectResult(responseMessage);
}

screenshot

Upvotes: 4

suziki
suziki

Reputation: 14088

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.

Upvotes: 3

Related Questions