@@ -2,24 +2,56 @@
3
3
5−Generate API docs for your *servant* webservice. Feel free to also take a look at [servant-pandoc](https://github.com/mpickering/servant-pandoc) which uses this package to target a broad range of output formats using the excellent **pandoc**.
5+Generate API docs for your _servant_ webservice. Feel free to also take a look at [servant-pandoc](https://github.com/mpickering/servant-pandoc) which uses this package to target a broad range of output formats using the excellent **pandoc**.
9See [here](https://github.com/haskell-servant/servant/blob/master/servant-docs/example/greet.md) for the output of the following program.
9See [here](https://github.com/haskell-servant/servant/blob/master/servant-docs/example/greet.md) for the output of the following program.
11−``` haskell
11+```haskell
12{-# LANGUAGE DataKinds #-}
12{-# LANGUAGE DataKinds #-}
13−{-# LANGUAGE PolyKinds #-}
14−{-# LANGUAGE TypeFamilies #-}
15{-# LANGUAGE DeriveGeneric #-}
13{-# LANGUAGE DeriveGeneric #-}
16−{-# LANGUAGE TypeOperators #-}
17{-# LANGUAGE FlexibleInstances #-}
14{-# LANGUAGE FlexibleInstances #-}
15+{-# LANGUAGE MultiParamTypeClasses #-}
18{-# LANGUAGE OverloadedStrings #-}
16{-# LANGUAGE OverloadedStrings #-}
17+{-# LANGUAGE PolyKinds #-}
18+{-# LANGUAGE TypeFamilies #-}
19+{-# LANGUAGE TypeOperators #-}
20−import Data.Proxy
21+import Data.Aeson (FromJSON, ToJSON)
22+import Data.Proxy (Proxy (..))
23+import Data.String.Conversions (cs)
21−import Data.Text
24+import Data.Text (Text)
25+import GHC.Generics (Generic)
22import Servant.Docs
40import Servant.Docs
24-- our type for a Greeting message
56-- our type for a Greeting message
25data Greet = Greet { _msg :: Text }
57data Greet = Greet { _msg :: Text }
@@ -29,6 +61,7 @@ data Greet = Greet { _msg :: Text }
29-- 'MimeRender' instance for 'JSON'.
61-- 'MimeRender' instance for 'JSON'.
30instance FromJSON Greet
62instance FromJSON Greet
31instance ToJSON Greet
63instance ToJSON Greet
33-- We can also implement 'MimeRender' explicitly for additional formats.
66-- We can also implement 'MimeRender' explicitly for additional formats.
34instance MimeRender PlainText Greet where
67instance MimeRender PlainText Greet where
@@ -36,8 +69,7 @@ instance MimeRender PlainText Greet where
37-- we provide a sample value for the 'Greet' type
70-- we provide a sample value for the 'Greet' type
38instance ToSample Greet where
71instance ToSample Greet where
39− toSample = Just g
72+ toSamples _ = singleSample g
41 where g = Greet "Hello, haskeller!"
73 where g = Greet "Hello, haskeller!"
43instance ToParam (QueryParam "capital" Bool) where
75instance ToParam (QueryParam "capital" Bool) where
@@ -45,6 +77,7 @@ instance ToParam (QueryParam "capital" Bool) where
45 DocQueryParam "capital"
77 DocQueryParam "capital"
46 ["true", "false"]
78 ["true", "false"]
47 "Get the greeting message in uppercase (true) or not (false). Default is false."
79 "Get the greeting message in uppercase (true) or not (false). Default is false."
49instance ToCapture (Capture "name" Text) where
82instance ToCapture (Capture "name" Text) where
50 toCapture _ = DocCapture "name" "name of the person to greet"
83 toCapture _ = DocCapture "name" "name of the person to greet"
@@ -55,8 +88,8 @@ instance ToCapture (Capture "greetid" Text) where
55-- API specification
88-- API specification
56type TestApi =
89type TestApi =
57 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON,PlainText] Greet
90 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON,PlainText] Greet
58− :<|> "greet" :> RQBody '[JSON] Greet :> Post '[JSON] Greet
91+ :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
59− :<|> "delete" :> Capture "greetid" Text :> Delete '[] ()
92+ :<|> "delete" :> Capture "greetid" Text :> Delete '[JSON] ()
61testApi :: Proxy TestApi
94testApi :: Proxy TestApi
62testApi = Proxy
95testApi = Proxy