Last active
November 14, 2018 20:55
-
-
Save vainolo/8c3bfdcd093e14ffba2370290dc0c4f9 to your computer and use it in GitHub Desktop.
Azure Functions – Part 6: Triggers and Bindings - 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Logging; | |
using Newtonsoft.Json; | |
namespace Vainolo.AzureFunctionsTutorial.Part6 | |
{ | |
public static class MyFunctions | |
{ | |
[FunctionName("HttpTrigger")] | |
public static async Task<IActionResult> HttpTrigger( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] 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"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment