Skip to content

Commit

Permalink
Improve Http message
Browse files Browse the repository at this point in the history
  • Loading branch information
merken committed Sep 10, 2020
1 parent 9083ef0 commit 98498b5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/Local.Functions/HttpTriggeredFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,22 @@ public static class HttpTriggeredFunction
{
[FunctionName("Http")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest request,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = request.Query["name"];

string name = req.Query["name"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
string requestBody = await new StreamReader(request.Body).ReadToEndAsync();
if (!String.IsNullOrEmpty(requestBody))
{
var data = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(requestBody);
name = name ?? data["name"];
if (data.ContainsKey("name"))
{
name = data["name"];
}
}

string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";

return new OkObjectResult(responseMessage);
return new OkObjectResult($"Received HTTP {request.Method}: {name}");
}
}
}

0 comments on commit 98498b5

Please sign in to comment.