Reputation: 14147
I am trying to set a query paramter in azure function v2. the Name query parameter remains null. What am I missing. The url I use in postman is http://localhost:7071/api/ScheduledJob/Frank
[FunctionName("ScheduledJob")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get",
Route = "{name}")] HttpRequest req,
ILogger log)
{
string name = req.Query["name"];
}
Upvotes: 0
Views: 274
Reputation: 26324
Your route definition is incorrect. Base URL defaults to /api
not /api/FunctionName
.
Use this -
Route = "ScheduledJob/{name}"
Now your URL becomes
http://localhost:7071/api/ScheduledJob/{name}
instead of
http://localhost:7071/api/{name}
which is what you have right now.
You also don't need to declare name
as a new variable in your code, use it in the binding instead:
[FunctionName("HttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post",
Route = "ScheduledJob/{name}")] HttpRequest req,
string name,
ILogger log)
{
return new OkObjectResult($"Hello, {name}");
}
$ curl http://localhost:7071/api/ScheduledJob/Frank
Hello, Frank
Upvotes: 1