I have a compiled Azure function and I want to define a custom route using the HttpTrigger attribute.
My code looks like this:
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "qotd/{format}")]HttpRequestMessage req, string format, TraceWriter log)
{
var quote = GetRandomQuote();
if (format == "json")
{
return req.CreateResponse(HttpStatusCode.OK, quote, "application/json");
}
else
{
var strQuote = quote.Text + Environment.NewLine + quote.Author;
return req.CreateResponse(HttpStatusCode.OK, strQuote, "text/plain");
}
}
When I call it like this: localhost:7071/api/qotd/json I get 404.
When I call it like this: localhost:7071/api/qotd/?format=json then the function succeeds.
If I call it like this: localhost:7071/api/qotd/ I get a rather nasty error:
"Exception while executing function: QotDFunction -> Exception binding parameter 'format' -> Binding data does not contain expected value 'format'..."
How can I define the binding in Route parameter of HttpTrigger, so that I can call my function like this:
localhost:7071/api/qotd - for a default value of parameter format
and
localhost:7071/api/qotd/json - to pass "json" as a value for format?
For Route I tried also "qotd/{format:alpha?}" but got the same results.

