Fix reversed path parts and add example case to test

This commit is contained in:
Greg Hale 2016-05-16 14:32:16 -04:00
parent 2d490df43a
commit 2e25bc64a8
4 changed files with 12 additions and 3 deletions

View File

@ -14,6 +14,7 @@ type API = "getunit" :> Get '[JSON] ()
:> Get '[JSON] String
:<|> "double" :> ReqBody '[JSON] Double
:> Post '[JSON] Double
:<|> "a" :> "b" :> QueryFlag "gusto" :> Get '[JSON] String
:<|> Raw
type GET = Get '[JSON] ()

View File

@ -30,7 +30,7 @@ run = do
el "br" (return ())
-- Name the computed API client functions
let (getUnit :<|> getInt :<|> sayhi :<|> dbl :<|> doRaw) =
let (getUnit :<|> getInt :<|> sayhi :<|> dbl :<|> multi :<|> doRaw) =
client api (Proxy :: Proxy m) url
elClass "div" "demo-group" $ do
@ -80,6 +80,13 @@ run = do
el "br" (return ())
display =<< holdDyn "No number yet" (fmap show $ fmapMaybe reqSuccess dblResp)
elClass "div" "demo-group" $ do
text "Multi-part path"
b <- (current . value) <$> checkbox False def
mpGo <- button "Test"
multiResp <- multi b mpGo
dynText =<< holdDyn "No res yet" (fmap show $ fmapMaybe reqSuccess $ multiResp)
showXhrResponse :: XhrResponse -> String
showXhrResponse (XhrResponse stat stattxt rbmay rtmay) =
unlines ["stat: " ++ show stat

View File

@ -99,7 +99,7 @@ performRequest reqMethod req reqHost trigger = do
-- Ridiculous functor-juggling! How to clean this up?
let t :: Behavior t [Either String String]
t = sequence $ reqPathParts req
t = sequence $ L.reverse $ reqPathParts req
baseUrl :: Behavior t (Either String String)
baseUrl = Right . showBaseUrl <$> current reqHost

View File

@ -44,7 +44,7 @@ data App = App
--
-- Each handler runs in the 'ExceptT ServantErr IO' monad.
server :: Server API (Handler App App)
server = return () :<|> return 100 :<|> sayhi :<|> dbl :<|> serveDirectory "static"
server = return () :<|> return 100 :<|> sayhi :<|> dbl :<|> multi :<|> serveDirectory "static"
where sayhi nm greetings withGusto = case nm of
Nothing -> return ("Sorry, who are you?" :: String)
Just n -> do
@ -56,6 +56,7 @@ server = return () :<|> return 100 :<|> sayhi :<|> dbl :<|> serveDirectory "stat
++ ", and " ++ L.last greetings ++ ", "
return . modifier $ greetPart ++ n
dbl x = return $ x * 2
multi = return . bool "Box unchecked" "Box Checked"
-- Turn the server into a WAI app. 'serve' is provided by servant,
-- more precisely by the Servant.Server module.