public static async Task Run()

in DeviceBridgeE2E/EchoAzureFunction/DeviceBridgeE2EEcho/DeviceBridgeE2EEcho.cs [24:57]


        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Called");
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            StringValues deviceIds;
            req.Query.TryGetValue("deviceId", out deviceIds);
            string deviceId = deviceIds.ToArray()[0];

            if (req.Method == "GET")
            {
                string outValue;
                cache.TryGetValue(deviceId, out outValue);
                return new OkObjectResult(outValue);
            } else if (req.Method == "POST")
            {
                if (cache.ContainsKey(deviceId))
                {
                    string value;
                    if (!cache.TryRemove(deviceId, out value))
                    {
                        return new ConflictObjectResult("Conflict when adding to dictionary");
                    }
                }
                cache.AddOrUpdate(deviceId, requestBody, (k, v) => requestBody);
            } else if(req.Method == "DELETE")
            {
                cache.TryRemove(deviceId, out _);
            }

            return new OkObjectResult("Undefined");
        }