1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE OverloadedStrings #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
16-- | A greet message data type
17newtype Greet = Greet { msg :: Text }
18 deriving (Generic, Show)
20instance FromJSON Greet
23-- We add some useful annotations to our captures,
24-- query parameters and request body to make the docs
26instance ToCapture (Capture "name" Text) where
27 toCapture _ = DocCapture "name" "name of the person to greet"
29instance ToCapture (Capture "greetid" Text) where
30 toCapture _ = DocCapture "greetid" "identifier of the greet msg to remove"
32instance ToParam (QueryParam "capital" Bool) where
34 DocQueryParam "capital"
36 "Get the greeting message in uppercase (true) or not (false). Default is false."
39instance ToSample Greet where
40 toSample = Just $ Greet "Hello, haskeller!"
43 [ ("If you use ?capital=true", Greet "HELLO, HASKELLER")
44 , ("If you use ?capital=false", Greet "Hello, haskeller")
47instance ToIntro "on proper introductions" where
48 toIntro _ = DocIntro "On proper introductions." -- The title
50 , "As documentation is usually written for humans, it's often useful \
51 \to introduce concepts with a few words." ] -- Elements are paragraphs
53instance ToIntro "on zebras" where
54 toIntro _ = DocIntro "This title is below the last"
55 [ "You'll also note that multiple intros are possible." ]
60 -- GET /hello/:name?capital={true, false} returns a Greet as JSON
61 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
63 -- POST /greet with a Greet as JSON in the request body,
64 -- returns a Greet as JSON
65 :<|> "greet" :> ReqBody Greet :> Post Greet
67 -- DELETE /greet/:greetid
68 :<|> "greet" :> Capture "greetid" Text :> Delete
71 Intro "on proper introductions" :> Intro "on zebras" :> TestApi
73introducedApi :: Proxy IntroducedApi
76-- Generate the data that lets us have API docs. This
77-- is derived from the type as well as from
78-- the 'ToCapture', 'ToParam' and 'ToSample' instances from above.
80docsGreet = docs introducedApi
83main = putStrLn $ markdown docsGreet
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