on tuple-api-2 help sign in
servant-reflex/exec/TupleExample.hs
35 lines 1.0 kB history raw
1{-# LANGUAGE RankNTypes #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeApplications #-}
9module TupleExample where
11import Data.Aeson
12import Data.Proxy
13import Data.Text
14import GHC.TypeLits
15import Reflex.Dom
16import Servant.API
17import Servant.Reflex.Tuple
19type TestAPI = Get '[JSON] Int
20 -- :<|> Post '[JSON] Int
21 :<|> Capture "name" Text :> Post '[JSON] Text
24run :: forall t m. (SupportsServantReflex t m, MonadWidget t m) => m ()
25run = do
26 let (getInt :<|> greet) = client (Proxy @TestAPI) (Proxy @m) (BasePath "/")
27 -- let getInt = client (Proxy @TestAPI) (Proxy @m) (BasePath "/")
28 b <- button "Go for it"
29 g <- ("greg" <$) <$> button "Hello"
30 -- g <- button "Hello"
31 b' <- getInt b
32 display =<< holdDyn (Left "Waiting") b'
33 g' <- greet g
34 display =<< holdDyn (Left "Waiting") g'