Skip to content

Instantly share code, notes, and snippets.

@angelo-marano
Created November 2, 2018 13:07
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 angelo-marano/fcc3cf1ab2b7370b76ee3c45468e2ad3 to your computer and use it in GitHub Desktop.
Save angelo-marano/fcc3cf1ab2b7370b76ee3c45468e2ad3 to your computer and use it in GitHub Desktop.
What you see when you start a new Azure function
public static class MyFirstFunction
{
[FunctionName("MyFirstFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] 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