Azure Functions でクラスを追加するとテンプレートについてくる例のやつをやるのが面倒になったのでサンプルコード置いておきます。 パフォーマンス無視したコードになるので利用する際は自己責任で。 あとDynamicJson使ってるので適宜。
before
[FunctionName("HelloWorld")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; return name != null ? (ActionResult)new OkObjectResult($"Hello, {name}") : new BadRequestObjectResult("Please pass a name on the query string or in the request body"); }
after
[FunctionName("HelloWorld")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var name = await req.GetParam<string>("name"); return name.result && name.value != null ? (ActionResult)new OkObjectResult($"Hello, {name.value}") : new BadRequestObjectResult("Please pass a name on the query string or in the request body"); }