Skip to content

Instantly share code, notes, and snippets.

@johndowns
Created November 7, 2018 10:58
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 johndowns/b172012521d1996bfcec0a4d071db4f5 to your computer and use it in GitHub Desktop.
Save johndowns/b172012521d1996bfcec0a4d071db4f5 to your computer and use it in GitHub Desktop.
[FunctionName("HelloWorld")]
public static async Task<IActionResult> HelloWorld(
[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");
}
[FunctionName("HelloQueue")]
[return: Queue("greetings")]
public static async Task<string> HelloQueue(
[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 $"Hello, {name}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment