module Imm.HTTP where
import Imm.Error
import Imm.Logger
import Imm.Prelude
import Imm.Pretty
import Control.Monad.Trans.Free
import URI.ByteString
data HttpClientF next
= Get URI (Either SomeException LByteString -> next)
deriving(Functor)
newtype CoHttpClientF m a = CoHttpClientF
{ getH :: URI -> m (Either SomeException LByteString, a)
} deriving(Functor)
instance Monad m => PairingM (CoHttpClientF m) HttpClientF m where
pairM p (CoHttpClientF g) (Get uri next) = do
(result, a) <- g uri
p a $ next result
get :: (MonadFree f m, HttpClientF :<: f, LoggerF :<: f, MonadThrow m)
=> URI -> m LByteString
get uri = do
logDebug $ "Fetching " <> prettyURI uri
result <- liftF . inj $ Get uri id
liftE result