3[](http://travis-ci.org/haskell-servant/servant-docs)
5
7Generate 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**.
11See [here](https://github.com/haskell-servant/servant-docs/blob/master/example/greet.md) for the output of the following program.
14{-# LANGUAGE DataKinds #-}
15{-# LANGUAGE PolyKinds #-}
16{-# LANGUAGE TypeFamilies #-}
17{-# LANGUAGE DeriveGeneric #-}
18{-# LANGUAGE TypeOperators #-}
19{-# LANGUAGE FlexibleInstances #-}
20{-# LANGUAGE OverloadedStrings #-}
26-- our type for a Greeting message
27data Greet = Greet { _msg :: Text }
28 deriving (Generic, Show)
30-- we get our JSON serialization for free. This will be used by the default
31-- 'MimeRender' instance for 'JSON'.
32instance FromJSON Greet
35-- We can also implement 'MimeRender' explicitly for additional formats.
36instance MimeRender PlainText Greet where
37 toByteString Proxy (Greet s) = "<h1>" <> cs s <> "</h1>"
39-- we provide a sample value for the 'Greet' type
40instance ToSample Greet where
43 where g = Greet "Hello, haskeller!"
45instance ToParam (QueryParam "capital" Bool) where
47 DocQueryParam "capital"
49 "Get the greeting message in uppercase (true) or not (false). Default is false."
51instance ToCapture (Capture "name" Text) where
52 toCapture _ = DocCapture "name" "name of the person to greet"
54instance ToCapture (Capture "greetid" Text) where
55 toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
59 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON,PlainText] Greet
60 :<|> "greet" :> RQBody '[JSON] Greet :> Post '[JSON] Greet
61 :<|> "delete" :> Capture "greetid" Text :> Delete
63testApi :: Proxy TestApi
66-- Generate the Documentation's ADT
68greetDocs = docs testApi
71main = 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