In this post, I am going to describe how you can create and deploy an Azure Function using Http Trigger.
- Open Visual Studio
- Click on New Project
- Select Azure Functions

- Select Azure v2 and HttpTrigger

-
public static class HelloFunctions
{
[FunctionName("HelloFunctions")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
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");
}
}