git.iko.soy/typeable/servant
on feef8ca help sign in
71 lines 2.0 kB history raw
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE TypeOperators #-}
7module T10 where
9import Data.ByteString.Lazy (ByteString)
10import Data.Text.Lazy (pack)
11import Data.Text.Lazy.Encoding (encodeUtf8)
12import Network.HTTP.Types
13import Network.Wai
14import Servant
15import Servant.Docs
16import qualified T3
18type DocsAPI = T3.API :<|> Raw
20instance ToCapture (Capture "x" Int) where
21 toCapture _ = DocCapture "x" "(integer) position on the x axis"
23instance ToCapture (Capture "y" Int) where
24 toCapture _ = DocCapture "y" "(integer) position on the y axis"
26instance ToSample T3.Position where
27 toSamples _ = singleSample (T3.Position 3 14)
29instance ToParam (QueryParam "name" String) where
30 toParam _ =
31 DocQueryParam "name"
32 ["Alp", "John Doe", "..."]
33 "Name of the person to say hello to."
34 Normal
36instance ToSample T3.HelloMessage where
37 toSamples _ =
38 [ ("When a value is provided for 'name'", T3.HelloMessage "Hello, Alp")
39 , ("When 'name' is not specified", T3.HelloMessage "Hello, anonymous coward")
40 ]
42ci :: T3.ClientInfo
43ci = T3.ClientInfo "Alp" "alp@foo.com" 26 ["haskell", "mathematics"]
45instance ToSample T3.ClientInfo where
46 toSamples _ = singleSample ci
48instance ToSample T3.Email where
49 toSamples _ = singleSample (T3.emailForClient ci)
51api :: Proxy DocsAPI
52api = Proxy
54docsBS :: ByteString
55docsBS = encodeUtf8
56 . pack
57 . markdown
58 $ docsWithIntros [intro] T3.api
60 where intro = DocIntro "Welcome" ["This is our super webservice's API.", "Enjoy!"]
62server :: Server DocsAPI
63server = T3.server :<|> serveDocs
65 where serveDocs _ respond =
66 respond $ responseLBS ok200 [plain] docsBS
68 plain = ("Content-Type", "text/plain")
70app :: Application
71app = serve api server