@@ -9,6 +9,7 @@
99{-# LANGUAGE TypeFamilies #-}
1010{-# LANGUAGE TypeOperators #-}
1111{-# LANGUAGE UndecidableInstances #-}
12+{-# LANGUAGE MultiParamTypeClasses #-}
1213
1314#include "overlapping-compat.h"
1415-- | This module provides 'client' which can automatically generate
@@ -50,7 +51,7 @@ import Reflex.Dom.Xhr
5051-- > myApi = Proxy
5152-- >
5253-- > getAllBooks :: Event t () -> m (Event t (Either XhrError ((),[Book])))
53−-- > postNewBook :: Behavior t (Maybe Book) -> Event t ()
54+-- > postNewBook :: Behavior t (Maybe Book) -> Event t ()
5455-- -> m (Event t (Either XhrError (Book,Book)))
5556-- > (getAllBooks :<|> postNewBook) = client myApi host
5657-- > where host = constDyn $ BaseUrl Http "localhost" 8080
@@ -60,41 +61,40 @@ client p baseurl = clientWithRoute p defReq baseurl
6061-- | This class lets us define how each API combinator
6162-- influences the creation of an HTTP request. It's mostly
6263-- an internal class, you can just use 'client'.
63−class HasClient layout where
64− type Client layout :: *
65− clientWithRoute :: Proxy layout -> Req -> BaseUrl -> Client layout
64+class HasClient t layout where
65+ type Client t layout :: *
66+ clientWithRoute :: Proxy layout -> Req t -> BaseUrl -> Client t layout
6667
6768
68−instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
69− type Client (a :<|> b) = Client a :<|> Client b
69+instance (HasClient t a, HasClient t b) => HasClient t (a :<|> b) where
70+ type Client t (a :<|> b) = Client t a :<|> Client t b
7071 clientWithRoute Proxy req baseurl manager =
71− clientWithRoute (Proxy :: Proxy a) req baseurl manager :<|>
72− clientWithRoute (Proxy :: Proxy b) req baseurl manager
72+ clientWithRoute (Proxy :: Proxy a) req baseurl :<|>
73+ clientWithRoute (Proxy :: Proxy b) req baseurl
7374
7475-- Capture. Example:
7576-- > type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
7677-- >
7778-- > myApi :: Proxy MyApi = Proxy
7879-- >
79−-- > getBook :: MonadWidget t m
80+-- > getBook :: MonadWidget t m
8081-- => Dynamic t BaseUrl
81−-- -> Behavior t (Maybe Text)
82+-- -> Behavior t (Maybe Text)
8283-- -> Event t ()
8384-- -> m (Event t (Either XhrError (Text, Book)))
8485-- > getBook = client myApi (constDyn host)
85−instance (KnownSymbol capture, ToHttpApiData a, HasClient sublayout)
86− => HasClient (Capture capture a :> sublayout) where
86+instance (Reflex t, KnownSymbol capture, ToHttpApiData a, HasClient t sublayout)
87+ => HasClient t (Capture capture a :> sublayout) where
8788
88− type Client (Capture capture a :> sublayout) =
89− a -> Client sublayout
89+ type Client t (Capture capture a :> sublayout) =
90+ Behavior t (Maybe a) -> Client t sublayout
9091
91− clientWithRoute Proxy req baseurl manager val =
92+ clientWithRoute Proxy req baseurl val =
9293 clientWithRoute (Proxy :: Proxy sublayout)
93− (appendToPath p req)
94+ (appendToPathParts p req)
9495 baseurl
95− manager
9696
97− where p = unpack (toUrlPiece val)
97+ where p = fmap (unpack . toUrlPiece) val
9898
9999-- VERB (Returning content) --
100100instance OVERLAPPABLE_