Last active
November 7, 2018 17:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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