git.iko.soy/typeable/servant
on master help sign in
servant-client-ghcjs: Throw exception on streamingRequest
4df71dcFalco Peijnenburg
servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs+28
@@ -35,6 +35,7 @@ import Data.IORef (modifyIORef, newIORef, readIORef)
35import Data.Proxy (Proxy (..))
35import Data.Proxy (Proxy (..))
36import qualified Data.Sequence as Seq
36import qualified Data.Sequence as Seq
37import Data.String.Conversions
37import Data.String.Conversions
38+import Data.Typeable (Typeable)
38import Foreign.StablePtr
39import Foreign.StablePtr
39import GHC.Generics
40import GHC.Generics
40import qualified GHCJS.Buffer as Buffer
41import qualified GHCJS.Buffer as Buffer
@@ -51,14 +52,34 @@ newtype JSXMLHttpRequest = JSXMLHttpRequest JSVal
51
52
52newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
53newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
53
54
55+-- | The environment in which a request is run.
54newtype ClientEnv
56newtype ClientEnv
55 = ClientEnv
57 = ClientEnv
56 { baseUrl :: BaseUrl }
58 { baseUrl :: BaseUrl }
57 deriving (Eq, Show)
59 deriving (Eq, Show)
58
60
61+-- | Generates a set of client functions for an API.
62+--
63+-- Example:
64+--
65+-- > type API = Capture "no" Int :> Get '[JSON] Int
66+-- > :<|> Get '[JSON] [Bool]
67+-- >
68+-- > api :: Proxy API
69+-- > api = Proxy
70+-- >
71+-- > getInt :: Int -> ClientM Int
72+-- > getBools :: ClientM [Bool]
73+-- > getInt :<|> getBools = client api
74+--
75+-- NOTE: Does not support constant space streaming of the request body!
59client :: HasClient ClientM api => Proxy api -> Client ClientM api
76client :: HasClient ClientM api => Proxy api -> Client ClientM api
60client api = api `clientIn` (Proxy :: Proxy ClientM)
77client api = api `clientIn` (Proxy :: Proxy ClientM)
61
78
79+-- | @ClientM@ is the monad in which client functions run. Contains the
80+-- 'BaseUrl' used for requests in the reader environment.
81+--
82+-- NOTE: Does not support constant space streaming of the request body!
62newtype ClientM a = ClientM
83newtype ClientM a = ClientM
63 { runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO) a }
84 { runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO) a }
64 deriving ( Functor, Applicative, Monad, MonadIO, Generic
85 deriving ( Functor, Applicative, Monad, MonadIO, Generic
@@ -79,8 +100,15 @@ instance MonadBaseControl IO ClientM where
79instance Alt ClientM where
100instance Alt ClientM where
80 a <!> b = a `catchError` const b
101 a <!> b = a `catchError` const b
81
102
103+data StreamingNotSupportedException = StreamingNotSupportedException
104+ deriving ( Typeable, Show )
105+
106+instance Exception StreamingNotSupportedException where
107+ displayException _ = "streamingRequest: streaming is not supported!"
108+
82instance RunClient ClientM where
109instance RunClient ClientM where
83 runRequest = performRequest
110 runRequest = performRequest
111+ streamingRequest _ = liftIO $ throwIO StreamingNotSupportedException
84 throwServantError = throwError
112 throwServantError = throwError
85
113
86instance ClientLike (ClientM a) (ClientM a) where
114instance ClientLike (ClientM a) (ClientM a) where