Skip to content

Instantly share code, notes, and snippets.

@vainolo
Last active November 14, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vainolo/8c3bfdcd093e14ffba2370290dc0c4f9 to your computer and use it in GitHub Desktop.
Save vainolo/8c3bfdcd093e14ffba2370290dc0c4f9 to your computer and use it in GitHub Desktop.
Azure Functions – Part 6: Triggers and Bindings - 1
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