Created
March 28, 2017 17:27
-
-
Save RobertFischer/2218c6b74451b5529189420a9c603722 to your computer and use it in GitHub Desktop.
What's wrong with this?
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 TemplateHaskell #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Lib | |
( startApp | |
, app | |
) where | |
import Data.Aeson | |
import Data.Aeson.TH | |
import Network.Wai | |
import Network.Wai.Handler.Warp | |
import Servant | |
data User = User | |
{ userId :: Int | |
, userFirstName :: String | |
, userLastName :: String | |
} deriving (Eq, Show) | |
$(deriveJSON defaultOptions ''User) | |
type API = "users" :> Capture "id" Integer :> Get '[JSON] [User] | |
startApp :: IO () | |
startApp = run 8080 app | |
app :: Application | |
app = serve api server | |
api :: Proxy API | |
api = Proxy | |
server :: Server API | |
server = return users | |
users :: Integer -> Handler [User] | |
users id = return $ [ User 1 "Isaac" "Newton", User 2 "Albert" "Einstein" ] |
Author
RobertFischer
commented
Mar 28, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment