Skip to content

Instantly share code, notes, and snippets.

@vainolo
Last active Nov 14, 2018
Embed
What would you like to do?
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