2015-08-17 23:56:29 +02:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2015-05-07 17:48:21 +02:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2015-05-10 13:39:18 +02:00
|
|
|
module T8 where
|
2015-05-07 17:48:21 +02:00
|
|
|
|
2015-08-17 23:56:29 +02:00
|
|
|
import Control.Monad.Trans.Either
|
|
|
|
import Data.Aeson
|
|
|
|
import Servant
|
|
|
|
import Servant.Client
|
2015-05-07 17:48:21 +02:00
|
|
|
|
2015-08-17 23:56:29 +02:00
|
|
|
import T3
|
2015-05-07 17:48:21 +02:00
|
|
|
|
|
|
|
position :: Int -- ^ value for "x"
|
|
|
|
-> Int -- ^ value for "y"
|
|
|
|
-> EitherT ServantError IO Position
|
|
|
|
|
|
|
|
hello :: Maybe String -- ^ an optional value for "name"
|
|
|
|
-> EitherT ServantError IO HelloMessage
|
|
|
|
|
|
|
|
marketing :: ClientInfo -- ^ value for the request body
|
|
|
|
-> EitherT ServantError IO Email
|
|
|
|
|
2015-05-09 17:31:54 +02:00
|
|
|
position :<|> hello :<|> marketing = client api baseUrl
|
2015-05-07 17:48:21 +02:00
|
|
|
|
|
|
|
baseUrl :: BaseUrl
|
2015-08-25 04:26:15 +02:00
|
|
|
baseUrl = BaseUrl Http "localhost" 8081 ""
|
2015-05-07 17:48:21 +02:00
|
|
|
|
|
|
|
queries :: EitherT ServantError IO (Position, HelloMessage, Email)
|
|
|
|
queries = do
|
2015-05-09 17:31:54 +02:00
|
|
|
pos <- position 10 10
|
|
|
|
msg <- hello (Just "servant")
|
|
|
|
em <- marketing (ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"])
|
2015-05-07 17:48:21 +02:00
|
|
|
return (pos, msg, em)
|
|
|
|
|
|
|
|
run :: IO ()
|
|
|
|
run = do
|
|
|
|
res <- runEitherT queries
|
|
|
|
case res of
|
|
|
|
Left err -> putStrLn $ "Error: " ++ show err
|
|
|
|
Right (pos, msg, em) -> do
|
|
|
|
print pos
|
|
|
|
print msg
|
|
|
|
print em
|