3
5Generate 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.
12{-# LANGUAGE DataKinds #-}
13{-# LANGUAGE DeriveGeneric #-}
14{-# LANGUAGE FlexibleInstances #-}
15{-# LANGUAGE MultiParamTypeClasses #-}
16{-# LANGUAGE OverloadedStrings #-}
17{-# LANGUAGE PolyKinds #-}
18{-# LANGUAGE TypeFamilies #-}
19{-# LANGUAGE TypeOperators #-}
21import Data.Aeson (FromJSON, ToJSON)
22import Data.Proxy (Proxy (..))
23import Data.String.Conversions (cs)
24import Data.Text (Text)
25import GHC.Generics (Generic)
56-- our type for a Greeting message
57data Greet = Greet { _msg :: Text }
58 deriving (Generic, Show)
60-- we get our JSON serialization for free. This will be used by the default
61-- 'MimeRender' instance for 'JSON'.
62instance FromJSON Greet
66-- We can also implement 'MimeRender' explicitly for additional formats.
67instance MimeRender PlainText Greet where
68 mimeRender Proxy (Greet s) = "<h1>" <> cs s <> "</h1>"
70-- we provide a sample value for the 'Greet' type
71instance ToSample Greet where
72 toSamples _ = singleSample g
73 where g = Greet "Hello, haskeller!"
75instance ToParam (QueryParam "capital" Bool) where
77 DocQueryParam "capital"
79 "Get the greeting message in uppercase (true) or not (false). Default is false."
82instance ToCapture (Capture "name" Text) where
83 toCapture _ = DocCapture "name" "name of the person to greet"
85instance ToCapture (Capture "greetid" Text) where
86 toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
90 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON,PlainText] Greet
91 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
92 :<|> "delete" :> Capture "greetid" Text :> Delete '[JSON] ()
94testApi :: Proxy TestApi
97-- Generate the Documentation's ADT
99greetDocs = docs testApi
102main = putStrLn $ markdown greetDocs
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