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"]; var servings = GetServings(req.Query["servings"]); if (name == null) { return(new BadRequestObjectResult("Please pass a name on the query string or in the request body")); } var comparer = new StringContainsComparer(); var cocktails = CocktailList.GetCocktails() .Where(c => CompareNames(c, name, comparer)) .Select(cocktail1 => cocktail1.ScaleIt(servings)); var json = JsonConvert.SerializeObject(cocktails, new StringEnumConverter()); return(new OkObjectResult(json)); }
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."); var qsIngredients = (string)req.Query["ingredients"]; var ingredients = qsIngredients.Split(','); var cocktails = CocktailList .GetCocktails() .Where(c => CheckForIngredient(c, ingredients)) .Select(c => c.Name); //string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); //dynamic data = JsonConvert.DeserializeObject(requestBody); //name = name ?? data?.name; var json = JsonConvert.SerializeObject(cocktails, new StringEnumConverter()); return(new OkObjectResult(json)); }