public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            [OrchestrationClient] DurableOrchestrationClient starter,
            ILogger log)
        {
            // get request params
            var postData = await req.ReadAsStringAsync();

            GameSessionRequest sessionParams = null;

            try
            {
                sessionParams = JsonConvert.DeserializeObject <GameSessionRequest>(postData);
            }
            catch (JsonException ex)
            {
                return(new BadRequestResult());
            }

            // get playerId
            int?playerId = null;

            if (sessionParams != null)
            {
                playerId = sessionParams.PlayerId;
                log.LogInformation($"The player identifier provided is: {playerId}");
            }
            else
            {
                return(new BadRequestResult());
            }

            // query db for session matching params
            string matchResult = null;

            if (playerId.HasValue)
            {
                matchResult = await DataClient.GetJoinableGameSessionGuid(playerId.Value.ToString());
            }

            if (matchResult == null)
            {
                // create session
                var    initialGameState = new GameSession(playerId.Value);
                string instanceId       = await starter.StartNewAsync("GameSession", initialGameState);

                // write game to db so other players can discover it
                await DataClient.AddGameSession(initialGameState, instanceId);

                log.LogInformation($"Started game session for player {playerId} with ID = '{instanceId}'.");

                matchResult = instanceId;
            }
            else
            {
                // send 'player join' event to session orchestrator
                await starter.RaiseEventAsync(matchResult, Constants.PlayerJoinEventTag, playerId);
            }

            return(new OkObjectResult(matchResult));
        }