I create an authenticated web API using Suave, and I often run into the problem of aggregating information in different functions.
pathScan Navigation.playersAvailables GetGame >>= getInSession >>= (fun (gameId,playerInSession) -> //access to both gameId and player in session)
Captions:
getGame : HttpContext -> Async<HttpContext option>
getInSession : HttpContext -> Async<HttpContext option>
- getGame take id from httpContext.request.querystring getInSession
- take sessionId from httpContext.cookie
The only thing I found for this is to store information in userDataDictionnary:
Writers.setUserData "player" { playerId= playersId; socialId=socialId; username = username}
And get it in another function, but it looks pretty unpleasant for me:
let player = x.userState.["player"] :?> PlayerSession
Is there any other way to do this? I would like to have pure functions like getGameId and get a session, etc. and be able to compose them since I want to handle different routes:
pathScan Navigation.playersAvailables GetGame >>= getInSession >>= (fun (gameId,playerInSession) -> //access to both gameId and player in session)
pathScan Navigation.otherRoute GetGame >>= (fun (gameId) -> //process gameId)
pathScan Navigation.otherRoute2 getInSession >>= (fun (sessionId) -> //process sessionId to do some other stuff)
I'm afraid that I need a daytime conversation with some real functional programmer.
source
share