Skip to content

Instantly share code, notes, and snippets.

@vainolo
Last active November 7, 2018 17:14
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 vainolo/27d266db056ce645e8438ec94765054d to your computer and use it in GitHub Desktop.
Save vainolo/27d266db056ce645e8438ec94765054d to your computer and use it in GitHub Desktop.
Azure Functions - Part 4: Working with Persistent Data and Visual Studio Code - 2
[FunctionName("SavingUserInput")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[Table("UserData")] out UserData ud,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string text = req.Query["text"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
text = text ?? data?.text;
ud = new UserData
{
PartitionKey = "1",
RowKey = DateTime.Now.Ticks.ToString(),
Text = text
};
return text != null
? (ActionResult)new OkObjectResult($"Hello, {text}")
: new BadRequestObjectResult("Please pass some text 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