Get Request from happstack-lite API
-
22-06-2021 - |
Question
How would I go about getting the Request data from the happstack-lite API? I'm trying to get the client's IP address. From what I can tell it's in Request::rqPeer, and I get confused trying to dive into the monadic-layers of the happstack API.
Solution
You can use askRq
in any ServerMonad to get at the Request, which you could pattern match on with record syntax to get the client hostname:
do Request {rqPeer = (host,_)} <- askRq
ok $ "Your IP: " ++ host
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow