haskellhaskell-snap-framework

How to send an http request using snap-framework?


I want to send an http request to an external API using the Snap framework. Does Snap support it? If not, how to go about it?


Solution

  • Have you looked at using Network.Wreq?

    import qualified Data.ByteString.Lazy as LAZ
    import qualified Data.ByteString.Lazy.Char8 as CHA
    
    makeRequest :: IO (Network.Wreq.Response LAZ.ByteString)
    makeRequest = do
       res <- get "https://www.example.com"
       let resBody = res ^. responseBody :: CHA.ByteString
       return (resBody)
    

    Uses simple lens syntax and supports HTTP and HTTPS.