@@ -0,0 +1,63 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE TypeFamilies #-}
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE TypeOperators #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE OverloadedStrings #-}
10+import Data.Foldable (foldMap)
15+import Servant.HTML.Lucid
18+ { firstName :: String
21+ } deriving Generic -- for the JSON instance
24+instance ToJSON Person
26+-- HTML serialization of a single person
27+instance ToHtml Person where
30+ td_ (toHtml $ firstName p)
31+ td_ (toHtml $ lastName p)
32+ td_ (toHtml . show $ age p)
36+-- HTML serialization of a list of persons
37+instance ToHtml [Person] where
38+ toHtml persons = table_ $ do
44+ foldMap toHtml persons
50+ [ Person "Isaac" "Newton" 372
51+ , Person "Albert" "Einstein" 136
54+type PersonAPI = "persons" :> Get '[JSON, HTML] [Person]
56+personAPI :: Proxy PersonAPI
59+server :: Server PersonAPI
60+server = return persons
63+app = serve personAPI server