@@ -35,6 +35,7 @@ import Data.IORef (modifyIORef, newIORef, readIORef)
35
35
import Data.Proxy (Proxy (.. ))
36
36
import qualified Data.Sequence as Seq
37
37
import Data.String.Conversions
38
+ import Data.Typeable (Typeable )
38
39
import Foreign.StablePtr
39
40
import GHC.Generics
40
41
import qualified GHCJS.Buffer as Buffer
@@ -51,14 +52,34 @@ newtype JSXMLHttpRequest = JSXMLHttpRequest JSVal
51
52
52
53
newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
53
54
55
+ -- | The environment in which a request is run.
54
56
newtype ClientEnv
55
57
= ClientEnv
56
58
{ baseUrl :: BaseUrl }
57
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!
59
76
client :: HasClient ClientM api => Proxy api -> Client ClientM api
60
77
client 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!
62
83
newtype ClientM a = ClientM
63
84
{ runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO ) a }
64
85
deriving ( Functor , Applicative , Monad , MonadIO , Generic
@@ -79,8 +100,15 @@ instance MonadBaseControl IO ClientM where
79
100
instance Alt ClientM where
80
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
+
82
109
instance RunClient ClientM where
83
110
runRequest = performRequest
111
+ streamingRequest _ = liftIO $ throwIO StreamingNotSupportedException
84
112
throwServantError = throwError
85
113
86
114
instance ClientLike (ClientM a ) (ClientM a ) where
0 commit comments