Created
February 18, 2017 05:50
-
-
Save naoto-ogawa/45d1676eb65818d84b31ba164e43daa0 to your computer and use it in GitHub Desktop.
simple servant sample
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 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