Created
May 30, 2019 08:08
-
-
Save throughnothing/68144d04e2f92fdc31a5fcbbd89306cc to your computer and use it in GitHub Desktop.
Servant with GADT types experiment
This file contains 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 GADTs #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Lib where | |
import Servant | |
import Servant.API () | |
data Query t where | |
GetInt :: Int -> Query Int | |
GetInts :: Query [Int] | |
-- | API Type | |
type QueryAPI t = | |
"query" :> ReqBody '[JSON] (Query t) :> Post '[JSON] t | |
server :: Server (QueryAPI t) | |
server = handleQuery | |
where | |
handleQuery :: Query t -> Handler t | |
handleQuery (GetInt i) = return i | |
handleQuery GetInts = return [1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment