-
Notifications
You must be signed in to change notification settings - Fork 0
/
Endpoints.hs
57 lines (39 loc) · 1.84 KB
/
Endpoints.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE DeriveGeneric, DataKinds, TypeOperators #-}
module Endpoints
( JsonToolsApi
, MinifyJob (..), MinifyRes (..)
, FormatJob (..), FormatRes (..)
, FilterJob (..), FilterRes (..)
, DiffJob (..), DiffRes (..)
) where
import Data.Text.Lazy (Text)
import Data.Aeson (Value,FromJSON,ToJSON)
import GHC.Generics (Generic)
import Servant.API ((:>),(:<|>),ReqBody,Post,JSON)
type JsonToolsApi = "minify" :> ReqBody '[JSON] MinifyJob :> Post '[JSON] MinifyRes
:<|> "format" :> ReqBody '[JSON] FormatJob :> Post '[JSON] FormatRes
:<|> "filter" :> ReqBody '[JSON] FilterJob :> Post '[JSON] FilterRes
:<|> "diff" :> ReqBody '[JSON] DiffJob :> Post '[JSON] DiffRes
-- :<|> "all" :> ReqBody '[JSON] _ :> Post '[JSON] _
newtype MinifyJob = MinifyJob { minifyPayload :: Value } deriving (Eq,Show,Generic)
newtype MinifyRes = MinifyRes { minifiedText :: Text} deriving (Eq,Show,Generic)
newtype FormatJob = FormatJob { formatPayload :: Value } deriving (Eq,Show,Generic)
newtype FormatRes = FormatRes { formattedText :: Text} deriving (Eq,Show,Generic)
data FilterJob = FilterJob { filterPayload :: Value
, filterKeys :: [Text]
} deriving (Eq,Show,Generic)
newtype FilterRes = FilterRes { filterResult :: Value } deriving (Eq,Show,Generic)
data DiffJob = DiffJob { diffPayloadA :: Value
, diffPayloadB :: Value
} deriving (Eq,Show,Generic)
data DiffRes = DiffRes { diffDeletions :: Value
, diffAdditions :: Value
} deriving (Eq,Show,Generic)
instance FromJSON MinifyJob
instance FromJSON FormatJob
instance FromJSON FilterJob
instance FromJSON DiffJob
instance ToJSON MinifyRes
instance ToJSON FormatRes
instance ToJSON FilterRes
instance ToJSON DiffRes