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 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).\
40instance ToParam (MatrixParam "lang" String) where
44 "Get the greeting message selected language. Default is en."
47instance ToSample Greet where
48 toSample = Just $ Greet "Hello, haskeller!"
51 [ ("If you use ?capital=true", Greet "HELLO, HASKELLER")
52 , ("If you use ?capital=false", Greet "Hello, haskeller")
56intro1 = DocIntro "On proper introductions." -- The title
58 , "As documentation is usually written for humans, it's often useful \
59 \to introduce concepts with a few words." ] -- Elements are paragraphs
62intro2 = DocIntro "This title is below the last"
63 [ "You'll also note that multiple intros are possible." ]
68 -- GET /hello/:name?capital={true, false} returns a Greet as JSON
69 "hello" :> MatrixParam "lang" String :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
71 -- POST /greet with a Greet as JSON in the request body,
72 -- returns a Greet as JSON
73 :<|> "greet" :> ReqBody Greet :> Post Greet
75 -- DELETE /greet/:greetid
76 :<|> "greet" :> Capture "greetid" Text :> Delete
78testApi :: Proxy TestApi
81extras :: ExtraInfo TestApi
83 safeInfo (Proxy :: Proxy ("greet" :> Capture "greetid" Text :> Delete)) $
84 defAction & headers <>~ ["unicorns"]
85 & notes <>~ [ DocNote "Title" ["This is some text"]
86 , DocNote "Second secton" ["And some more"]
89-- Generate the data that lets us have API docs. This
90-- is derived from the type as well as from
91-- the 'ToCapture', 'ToParam' and 'ToSample' instances from above.
93-- If you didn't want intros you could just call:
97docsGreet = docsWith [intro1, intro2] extras testApi
100main = 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