@@ -63,8 +63,8 @@ import Reflex.Dom.Xhr
6363client :: HasReflexClient layout
6464 => Proxy layout
6565 -> BaseUrl
66− -- -> Input layout
67− -> Client (Input layout) (Output layout)
66+-- -> Client (Input layout) (Output layout)
67+ -> Client layout
6868client p baseurl = clientWithRoute p defReq baseurl
6969
7070data a ::> b = a ::> b deriving (Eq,Ord,Show,Read)
@@ -72,7 +72,7 @@ data a ::> b = a ::> b deriving (Eq,Ord,Show,Read)
7272infixr 3 ::>
7373
7474
75−type Client ins outs = MonadWidget t m => Event t ins -> m (Event t (ins,outs))
75+-- type Client ins outs = MonadWidget t m => Event t ins -> m (Event t (ins,outs))
7676
7777-- | This class lets us define how each API combinator
7878-- influences the creation of an HTTP request. It's mostly
@@ -80,8 +80,10 @@ type Client ins outs = MonadWidget t m => Event t ins -> m (Event t (ins,outs))
8080class HasReflexClient layout where
8181 type Input layout :: *
8282 type Output layout :: *
83− clientWithRoute :: Proxy layout -> Req -> BaseUrl -- -> Input layout
84− -> Client (Input layout) (Output layout)
83+ type Client layout :: *
84+ type Client layout = MonadWidget t m => Event t (Input layout) -> m (Event t (Output layout))
85+ clientWithRoute :: MonadWidget t m => Proxy layout -> Req -> BaseUrl
86+ -> Event t (Input layout) -> m (Event t (Input layout, Output layout))
8587
8688
8789-- | If you have a 'Get' endpoint in your API, the client
@@ -95,6 +97,7 @@ instance
9597 (MimeUnrender ct result) => HasReflexClient (Get (ct ': cts) result) where
9698 type Input (Get (ct ': cts) result) = ()
9799 type Output (Get (ct ': cts) result) = result
100+ -- type Client (Get (ct ': cts) result) = MonadWidget t m => Event t (Input layout) -> m (Event t result)
98101 clientWithRoute Proxy req baseurl trigEvents = undefined -- performAJAX requestBuilder responseParser
99102-- where
100103-- requestBuilder _ = XhrRequest "GET" (showBaseUrl baseurl) def
@@ -122,6 +125,7 @@ instance
122125 HasReflexClient (Get (ct ': cts) ()) where
123126 type Input (Get (ct ': cts) ()) = ()
124127 type Output (Get (ct ': cts) ()) = ()
128+ -- type Client (Get (ct ': cts) ()) = MonadWidget t m => Event t () -> m (Event t ())
125129 clientWithRoute Proxy req baseurl trigEvents =
126130 performAJAX requestBuilder responseParser trigEvents
127131 where
@@ -154,27 +158,28 @@ instance
154158-- , getHeadersHList = buildHeadersTo hdrs
155159-- }
156160--
157−-- -- | A client querying function for @a ':<|>' b@ will actually hand you
158−-- -- one function for querying @a@ and another one for querying @b@,
159−-- -- stitching them together with ':<|>', which really is just like a pair.
160−-- --
161−-- -- > type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
162−-- -- > :<|> "books" :> ReqBody '[JSON] Book :> Post Book -- POST /books
163−-- -- >
164−-- -- > myApi :: Proxy MyApi
165−-- -- > myApi = Proxy
166−-- -- >
167−-- -- > getAllBooks :: ExceptT String IO [Book]
168−-- -- > postNewBook :: Book -> ExceptT String IO Book
169−-- -- > (getAllBooks :<|> postNewBook) = client myApi host
170−-- -- > where host = BaseUrl Http "localhost" 8080
171−-- instance (HasReflexClient a, HasReflexClient b) => HasReflexClient (a :<|> b) where
172−-- type Input (a :<|> b) = Input a :<|> Input b
173−-- type Client (a :<|> b) = Client a :<|> Client b
174−-- clientWithRoute Proxy req baseurl (a :<|> b) =
175−-- clientWithRoute (Proxy :: Proxy a) req baseurl a :<|>
176−-- clientWithRoute (Proxy :: Proxy b) req baseurl b
161+-- | A client querying function for @a ':<|>' b@ will actually hand you
162+-- one function for querying @a@ and another one for querying @b@,
163+-- stitching them together with ':<|>', which really is just like a pair.
177164--
165+-- > type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
166+-- > :<|> "books" :> ReqBody '[JSON] Book :> Post Book -- POST /books
167+-- >
168+-- > myApi :: Proxy MyApi
169+-- > myApi = Proxy
170+-- >
171+-- > getAllBooks :: ExceptT String IO [Book]
172+-- > postNewBook :: Book -> ExceptT String IO Book
173+-- > (getAllBooks :<|> postNewBook) = client myApi host
174+-- > where host = BaseUrl Http "localhost" 8080
175+instance (HasReflexClient a, HasReflexClient b) => HasReflexClient (a :<|> b) where
176+ type Input (a :<|> b) = Input a :<|> Input b
177+ -- type Output (a :<|> b) = Output a :<|> Output b
178+ type Client (a :<|> b) = (Client a :<|> Client b)
179+ clientWithRoute Proxy req baseurl (a :<|> b) =
180+ clientWithRoute (Proxy :: Proxy a) req baseurl a :<|>
181+ clientWithRoute (Proxy :: Proxy b) req baseurl b
182+
178183-- ------------------------------------------------------------------------------
179184-- -- | If you use a 'Capture' in one of your endpoints in your API,
180185-- -- the corresponding querying function will automatically take
@@ -574,18 +579,18 @@ instance
574579-- )
575580-- baseurl rest
576581--
577−-- -- | Make the querying function append @path@ to the request path.
578−-- instance (KnownSymbol path, HasReflexClient sublayout) => HasReflexClient (path :> sublayout) where
579−-- type Input (path :> sublayout) = Input sublayout
580−-- type Client (path :> sublayout) = Client sublayout
581−--
582−-- clientWithRoute Proxy req baseurl val =
583−-- clientWithRoute (Proxy :: Proxy sublayout)
584−-- (appendToPath p req)
585−-- baseurl val
586−--
587−-- where p = symbolVal (Proxy :: Proxy path)
588−--
582+-- | Make the querying function append @path@ to the request path.
583+instance (KnownSymbol path, HasReflexClient sublayout) => HasReflexClient (path :> sublayout) where
584+ type Input (path :> sublayout) = Input sublayout
585+ --type Output (path :> sublayout) = Output sublayout
586+ type Client (path :> sublayout) = Client sublayout
587+ clientWithRoute Proxy req baseurl val =
588+ clientWithRoute (Proxy :: Proxy sublayout)
589+ (appendToPath p req)
590+ baseurl val
591+
592+ where p = symbolVal (Proxy :: Proxy path)
593+
589594-- instance HasReflexClient api => HasReflexClient (Vault :> api) where
590595-- type Input (Vault :> api) = Input api
591596-- type Client (Vault :> api) = Client api