0

I have an Azure Function(V3) and I want to set a customer HTTP rout. I ended up with something like this:

[FunctionName(nameof(GetSomething))]
    public async Task<IActionResult> GetSomething(
        [HttpTrigger(AuthorizationLevel.Function, "get",
            Route = "api/v1/a/b/{bName}/{locationList}?name={name?}&fromDate={fromDate?}&toDate={toDate?}")] HttpRequest req, ILogger log, 
        string bName, string locationList, string name, string fromDate, string toDate)
    {
           //body
    }

I want to make those values after the {locationList} optional and give more flexibility for using that URL. However, the rout is not acceptable by the WebJob and the reason is the question mark '?' after {locationList}

"api/v1/a/b/{bName}/{locationList}?name={name?}&fromDate={fromDate?}&toDate={toDate?}"

I found a similar question here. I am not following the answer. Does anyone have a better solution or at least an example of this part

If it's the reason why you want to put query parameter in route, I would suggest you add IDictionary query in method signature and use query["manufacturer"] to access the parameter in function code. But honestly it's almost the same as request.Query["manufacturer"].

Krish
  • 648
  • 1
  • 8
  • 17
ShrnPrmshr
  • 353
  • 2
  • 5
  • 17
  • Don't know if this can be helpful (or it works): try setting ...`, string name = null, string fromDate = null, string toDate = null` in your signature. – Emanuele Nov 28 '19 at 13:44
  • @Emanuele does not work! – ShrnPrmshr Nov 28 '19 at 13:52
  • 3
    why do you need to include the query params at all in your route? if they are optional anyway, you can just read them in the function body from the `req` object – silent Nov 28 '19 at 14:51
  • @silent this exactly what I asked myself. so I ended up moving that to the body – ShrnPrmshr Nov 28 '19 at 15:19

0 Answers0