Last active
January 2, 2019 23:08
-
-
Save alpmestan/16b0473975b2e640364949b306cd23c3 to your computer and use it in GitHub Desktop.
Anonymous """value-level""" servant API type definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TypeOperators #-} | |
import Data.Proxy | |
import GHC.TypeLits | |
import Servant.API | |
infixr 9 >:> | |
infixr 8 <||> | |
(>:>) :: Proxy a -> Proxy b -> Proxy (a :> b) | |
Proxy >:> Proxy = Proxy | |
(<||>) :: Proxy a -> Proxy b -> Proxy (a :<|> b) | |
Proxy <||> Proxy = Proxy | |
path | |
:: KnownSymbol s | |
=> Proxy s | |
path = Proxy | |
capture | |
:: KnownSymbol s | |
=> Proxy (Capture s a) | |
capture = Proxy | |
get | |
:: Proxy (Get cts a) | |
get = Proxy | |
-- example | |
api = path @"hello" >:> capture @"userid" @Int >:> get @'[JSON] @String | |
<||> path @"bye" >:> capture @"userid" @Int >:> get @'[JSON] @String | |
-- and then call 'serve api ...' or 'docsFor api' or 'client api' or ... | |
{- | |
*Main λ> :t api | |
api | |
:: Proxy | |
(("hello" :> (Capture "userid" Int :> Get '[JSON] String)) | |
:<|> ("bye" :> (Capture "userid" Int :> Get '[JSON] String))) | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment