1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE TypeFamilies #-}
4{-# LANGUAGE TypeOperators #-}
7import Control.Monad.Trans.Except
14data Position = Position
17 } deriving (Show, Generic)
19instance FromJSON Position
20instance ToJSON Position
22newtype HelloMessage = HelloMessage { msg :: String }
23 deriving (Show, Generic)
25instance FromJSON HelloMessage
26instance ToJSON HelloMessage
28data ClientInfo = ClientInfo
32 , interested_in :: [String]
33 } deriving (Show, Generic)
35instance FromJSON ClientInfo
36instance ToJSON ClientInfo
43 } deriving (Show, Generic)
45instance FromJSON Email
48emailForClient :: ClientInfo -> Email
49emailForClient c = Email from' to' subject' body'
51 where from' = "great@company.com"
53 subject' = "Hey " ++ name c ++ ", we miss you!"
54 body' = "Hi " ++ name c ++ ",\n\n"
55 ++ "Since you've recently turned " ++ show (age c)
56 ++ ", have you checked out our latest "
57 ++ intercalate ", " (interested_in c)
58 ++ " products? Give us a visit!"
60type API = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
61 :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
62 :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email
72 where position :: Int -> Int -> ExceptT ServantErr IO Position
73 position x y = return (Position x y)
75 hello :: Maybe String -> ExceptT ServantErr IO HelloMessage
76 hello mname = return . HelloMessage $ case mname of
77 Nothing -> "Hello, anonymous coward"
78 Just n -> "Hello, " ++ n
80 marketing :: ClientInfo -> ExceptT ServantErr IO Email
81 marketing clientinfo = return (emailForClient clientinfo)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list