I want to persist some data in StateT monad,
Within Handler
of the post
(any http method) function I want to modify the data stored in state... but the issue is I can't use State inside Handler...
newtype HandlerM a = HandlerM (Request -> Response -> Effect Unit -> Aff a)
type Handler = HandlerM Unit
and type of http methods are as follows,
post :: forall r. RoutePattern r => r -> Handler -> App
I want to do something like,
post "/some/api" $ do
S.modify (\s -> s { count = s.+ 1}} ---- modify state with respect to response
--- handle request
ps: I can use ref
but is there any way I can use StateT inside Handler...
No, you'd have to use a Ref
for this - State
doesn't work in situations like this.
If you could plumb it through, what would happen is each request being processed would operate in its own State
, starting over with the initial value each time.