{-# LANGUAGE OverloadedStrings, FlexibleContexts, CPP #-}
module Network.Api.Support.Core (
runRequest
, runRequest'
, runRequestWith
, runRequestWith'
) where
import Network.Api.Support.Request
import Network.Api.Support.Response
import Control.Monad
import Data.Text
import Data.Monoid
import Network.HTTP.Client
import Network.HTTP.Types
runRequest ::
ManagerSettings
-> StdMethod
-> Text
-> RequestTransformer
-> Responder b
-> IO b
runRequest settings stdmethod url transform =
runRequest' settings url (transform <> setMethod (renderStdMethod stdmethod))
runRequestWith ::
Manager
-> StdMethod
-> Text
-> RequestTransformer
-> Responder b
-> IO b
runRequestWith manager stdmethod url transform =
runRequestWith' manager url (transform <> setMethod (renderStdMethod stdmethod))
runRequest' ::
ManagerSettings
-> Text
-> RequestTransformer
-> Responder b
-> IO b
runRequest' settings url transform responder = do
manager <- newManager settings
runRequestWith' manager url transform responder
runRequestWith' ::
Manager
-> Text
-> RequestTransformer
-> Responder b
-> IO b
runRequestWith' manager url transform responder =
#if MIN_VERSION_http_client(0,4,30)
do url'' <- parseRequest $ unpack url
#else
do url' <- parseUrl $ unpack url
let url'' = url' { checkStatus = const . const . const $ Nothing }
#endif
let req = appEndo transform url''
liftM (responder req) $ httpLbs req manager