Skip to content

Instantly share code, notes, and snippets.

@throughnothing
Created May 30, 2019 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save throughnothing/68144d04e2f92fdc31a5fcbbd89306cc to your computer and use it in GitHub Desktop.
Save throughnothing/68144d04e2f92fdc31a5fcbbd89306cc to your computer and use it in GitHub Desktop.
Servant with GADT types experiment
{-#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