Last active
February 26, 2020 13:17
-
-
Save abdolence/bf817429a8ed8245c18cdb7d07f12034 to your computer and use it in GitHub Desktop.
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 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