-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPI.hs
More file actions
33 lines (25 loc) · 874 Bytes
/
API.hs
File metadata and controls
33 lines (25 loc) · 874 Bytes
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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
module API
( API
, DeviceAPI
) where
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8)
import Servant
import Servant.Server.Experimental.Auth
import qualified Database as DB
import Device
import Statistics
type DeviceAPI =
"command" :> Get '[JSON] CommandAction
:<|> "measurement" :> ReqBody '[JSON] Measurement :> Post '[JSON] NoContent
type UnprotectedAPI = "login" :> ReqBody '[JSON] LoginRequest :> Post '[JSON] LoginRequest
:<|> "statistics" :> Get '[JSON] Statistics
type API = UnprotectedAPI :<|> AuthProtect "cookie-auth" :> DeviceAPI
-- | A value holding our type-level API
genAPI :: Proxy API
genAPI = Proxy
-- | We need to specify the data returned after authentication
type instance AuthServerData (AuthProtect "cookie-auth") = DeviceId