Create a gist now

Instantly share code, notes, and snippets.

simple servant sample
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
import Data.Aeson.Types
import Data.Aeson.Parser
import GHC.Generics
import Network.Wai.Handler.Warp
import Servant
data MyData = MyData { id :: Int, name :: String} deriving (Eq, Show, Generic)
instance ToJSON MyData
type MyAPI = "myapi" :> Get '[JSON] [MyData]
myInfo :: [MyData]
myInfo = [MyData 1 "abc"]
myServer :: Server MyAPI
myServer = return myInfo
myProxy :: Proxy MyAPI
myProxy = Proxy
myApp :: Application
myApp = serve myProxy myServer
main :: IO ()
main = run 8081 myApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment