@@ -0,0 +1,45 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE TypeOperators #-}
7+import Data.Time.Calendar
9+import Network.Wai.Handler.Warp (run)
16+ , registration_date :: Day
17+ } deriving (Eq, Show, Generic)
19+-- orphan ToJSON instance for Day. necessary to derive one for User
20+instance ToJSON Day where
21+ -- display a day in YYYY-mm-dd format
22+ toJSON d = toJSON (showGregorian d)
26+type UserAPI = "users" :> Get '[JSON] [User]
30+ [ User "Isaac Newton" 372 "isaac@newton.co.uk" (fromGregorian 1683 3 1)
31+ , User "Albert Einstein" 136 "ae@mc2.org" (fromGregorian 1905 12 1)
34+userAPI :: Proxy UserAPI
37+server :: Server UserAPI
40+runServer :: Int -> IO ()
41+runServer port = run port (serve userAPI server)