module Session exposing (Session(..), init, playerSession) import Browser.Navigation as Nav import Http import Json.Decode as D type Session = Player Nav.Key Int -- | Admin Nav.Key playerSession navKey playerId = Player navKey playerId init : (Maybe Session -> msg) -> Nav.Key -> Cmd msg init toMsg navKey = let toSession : Result Http.Error String -> msg toSession response = case Debug.log "got session:" response of Ok value -> case String.toInt value of Just id -> toMsg <| Just (Player navKey id) Nothing -> toMsg Nothing Err _ -> toMsg Nothing in Http.get { url = "http://localhost:8088/session" , expect = Http.expectJson toSession D.string }