git.iko.soy/typeable/servant-reflex
on master help sign in
Don't require FromHttpApiData instances for payload types
commitf260161babf9c1ceb6e19e8b68b399966d5811fe author3noch <elliot.cameron@level12.io> dateWed 30 Mar 2016, 11:19 (11 years ago) parent58922dd
3 files changed+10−11
README.md+8−8 src/Servant/Common/Req.hs+1−2 src/Servant/Reflex.hs+1−1
README.md+8−8
@@ -50,15 +50,15 @@ type API = "getint" :> Get '[JSON] Int
5050 :<|> Raw
5151```
5252
53−`servant-reflex` then computes functions that can query the API through an `XhrRequest`.
53+`servant-reflex` then computes functions that can query the API through an `XhrRequest`.
5454
5555```haskell
5656
5757 runGUI :: forall t m.MonadWidget t m => do
5858
5959 -- servant-reflex computes FRP functions for each API endpoint
60− let (getint :<|> sayhi :<|> doubleit :<|> _) = client (Proxy :: Proxy API)
61− (Proxy :: Proxy m)
60+ let (getint :<|> sayhi :<|> doubleit :<|> _) = client (Proxy :: Proxy API)
61+ (Proxy :: Proxy m)
6262 (constDyn defaultUrl)
6363```
6464
@@ -66,10 +66,10 @@ These client functions are computed from the API and manage serialization, XhrRe
6666
6767```haskell
6868 -- No need to write these functions. servant-reflex creates them for you!
69− getint :: MonadWidget t m
69+ getint :: MonadWidget t m
7070 => Event t () -- ^ Trigger the XHR Request
7171 -> m (Event t (Maybe (Int, XhrResponse))) -- ^ Consume the answer
72−
72+
7373 sayhi :: MonadWidget t m
7474 => Behavior t (Maybe String) -- ^ One input parameter - the 'name'
7575 -> Behavior t [String] -- ^ Another input - list of preferred greetings
@@ -90,7 +90,7 @@ Plug any of these functions into your reactive frontend to consume backend servi
9090 intButton <- button "Get Int"
9191 serverInts <- fmap fst <$> getint intButton
9292 display =<< holdDyn (Just 0) serverInts
93−
93+
9494 elClass "div" "hello-demo" $ do
9595 nameText <- (current . value) <$> textInput def
9696 greetings <- (fmap words . current . value) <$> textInput def
@@ -98,7 +98,7 @@ Plug any of these functions into your reactive frontend to consume backend servi
9898 helloButton <- button "Say hi"
9999 hellos <- fmap fst <$> sayhi nameText greetings withGusto helloButton
100100 display =<< holdDyn Nothing hellos
101−
101+
102102 elClass "div" "demo-double" $ do
103103 inputDouble <- (fmapMaybe readMaybe . current) <$> textInput def
104104 doubleButton <- button "Double it"
@@ -114,7 +114,7 @@ The frontend's widgets are sometimes in a state where a valid XHR request can be
114114
115115## Invalid responses
116116
117−For convenience, successful XHR responses are decoded into a `FromHttpAPIData a => Just a`. The `XHRResponse` is also returned, which you can inspect to get more fine-grained information about the response.
117+For convenience, successful XHR responses are decoded into a `MimeUnrender ct a => Just a`. The `XHRResponse` is also returned, which you can inspect to get more fine-grained information about the response.
118118
119119## TODOs
120120
src/Servant/Common/Req.hs+1−2
@@ -169,7 +169,7 @@ performRequestNoBody reqMethod req reqHost trigger = do
169169 undefined
170170 -- return hdrs
171171
172−performRequestCT :: (MonadWidget t m, FromHttpApiData a, MimeUnrender ct a)
172+performRequestCT :: (MonadWidget t m, MimeUnrender ct a)
173173 => Proxy ct -> String -> Req t -> Dynamic t BaseUrl
174174 -> Event t () -> m (Event t (Maybe a, XhrResponse))
175175performRequestCT ct reqMethod req reqHost trigger = do
@@ -261,4 +261,3 @@ performRequestCT ct reqMethod req reqHost trigger = do
261261-- | not . null . reqAccept $ req] }
262262-- toProperHeader (name, val) =
263263-- (fromString name, encodeUtf8 val)
264−
src/Servant/Reflex.hs+1−1
@@ -104,7 +104,7 @@ instance (MonadWidget t m, KnownSymbol capture, ToHttpApiData a, HasClient t m s
104104-- VERB (Returning content) --
105105instance {-# OVERLAPPABLE #-}
106106 -- Note [Non-Empty Content Types]
107− (MimeUnrender ct a, FromHttpApiData a, ReflectMethod method, cts' ~ (ct ': cts), MonadWidget t m
107+ (MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts), MonadWidget t m
108108 ) => HasClient t m (Verb method status cts' a) where
109109 type Client t m (Verb method status cts' a) =
110110 Event t () -> m (Event t (Maybe a, XhrResponse))