soostone/lib/Soostone/API.hs

37 lines
865 B
Haskell

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
module Soostone.API where
import Soostone.Types ( Count, Key )
import Servant
( Proxy(..),
JSON,
type (:>),
ReqBody,
Post,
QueryParam',
Required,
Strict,
Get,
NamedRoutes )
import Servant.API.Generic ( Generic, GenericMode(type (:-)) )
type SoostoneAPI = NamedRoutes API
type APIVersion = "v1"
data API mode = API {
mainAPI :: mode :- "api" :> APIVersion :> NamedRoutes MainAPI
} deriving Generic
data MainAPI mode = MainAPI {
submitKey :: mode :- "input" :> ReqBody '[JSON] Key :> Post '[JSON] ()
, countKey :: mode :- "query" :> QueryParam' '[Required, Strict] "key" Key :> Get '[JSON] Count
} deriving Generic
api :: Proxy SoostoneAPI
api = Proxy :: Proxy SoostoneAPI