1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TypeOperators #-}
8import Data.Aeson.Types (typeMismatch)
12newtype Question = Question { unQuestion :: Text } deriving (Show)
14instance ToJSON Question where
15 toJSON (Question txt) = object ["question" .= txt]
17instance FromJSON Question where
18 parseJSON (Object v) = Question <$> v .: "question"
19 parseJSON x = typeMismatch "Couldn't find key 'question'" x
26instance ToJSON Answer where
27 toJSON (Answer txt crt) = object ["answer" .= txt, "certainty" .= crt]
29instance FromJSON Answer where
30 parseJSON (Object v) = Answer <$> v .: "answer" <*> v .: "certainty"
31 parseJSON x = typeMismatch "Parse error" x
34-- | API spec for server, client, and docs
35type API = "getunit" :> Get '[JSON] ()
36 :<|> "getint" :> Get '[JSON] Int
37 :<|> "sayhi" :> QueryParam "username" Text
38 :> QueryParams "greetings" Text
41 :<|> "double" :> ReqBody '[JSON] Double
42 :> Post '[JSON] Double
43 :<|> "a" :> "b" :> QueryFlag "gusto" :> Get '[JSON] Text
44 :<|> "qna" :> ReqBody '[JSON] Question
45 :> Post '[JSON] Answer
48type GET = Get '[JSON] ()
50-- Imported the comprehensive API example for testing.
51-- https://github.com/haskell-servant/servant/blob/master/servant/src/Servant/API/Internal/Test/ComprehensiveAPI.hs
52type ComprehensiveAPI =
55 Capture "foo" Int :> GET :<|>
56 Header "foo" Int :> GET :<|>
57 HttpVersion :> GET :<|>
59 QueryParam "foo" Int :> GET :<|>
60 QueryParams "foo" Int :> GET :<|>
61 QueryFlag "foo" :> GET :<|>
63 RemoteHost :> GET :<|>
64 ReqBody '[JSON] Int :> GET :<|>
65 Get '[JSON] (Headers '[Header "foo" Int] ()) :<|>
68 Verb 'POST 204 '[JSON] () :<|>
69 Verb 'POST 204 '[JSON] Int
70-- This one isn't in scope
71-- :<|> WithNamedContext "foo" '[] GET
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