Example 1:
run.csx
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(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;
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);
}
https://test01.azurewebsites.net/api/HttpTrigger1?code=1OKiCpRMzBoxZ/BJ4W5DtVsoucEY7D0/YaPOi6wUjQDRwOChaN672g==&name=mike
Hello, mike. This HTTP triggered function executed successfully.
- The URL parameter “code” is the function key that needs to be passed in order to run the function.
- Multiple trigger options, http or timer or a list of other methods.
- Each function have its own code and can be enabled/disabled.
Example 2:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
string name = req.Query["name"];
string responseMessage = "Hello, " + name;
return new OkObjectResult(responseMessage);
}
Hello, mike
Comments