Skip to content

Instantly share code, notes, and snippets.

@abdolence
Last active February 26, 2020 13:17
Show Gist options
  • Save abdolence/bf817429a8ed8245c18cdb7d07f12034 to your computer and use it in GitHub Desktop.
Save abdolence/bf817429a8ed8245c18cdb7d07f12034 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Main where
import GHC.Generics
import Data.Aeson(ToJSON)
import Web.Scotty (ActionM, ScottyM, get, header, scotty, scottyApp, status, json, middleware, html)
import Network.HTTP.Types.Status
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
data MyTestData = MyTestData
{ id :: Int,
name :: String
} deriving (Generic, Show)
instance ToJSON MyTestData
createSimpleTestData :: MyTestData
createSimpleTestData = MyTestData { id = 1, name = "MyName" }
testJson :: ScottyM ()
testJson = get "/my-test-data" $ json createSimpleTestData
checkStatus :: ScottyM ()
checkStatus = get "/check" $ status status200
home :: ScottyM ()
home = get "/" $ html "Hey there!"
serverRoutes :: ScottyM ()
serverRoutes = do
middleware logStdoutDev
home
testJson
checkStatus
runServer :: IO()
runServer = scotty 8080 serverRoutes
main :: IO ()
main = runServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment