Created
October 5, 2017 22:56
-
-
Save rlucha/101fbea2d0a5a6496b0b197e8a07791a to your computer and use it in GitHub Desktop.
-- Scotty server example
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 OverloadedStrings #-} | |
| -- | |
| -- module Main where | |
| -- | |
| -- import Web.Scotty | |
| -- import Control.Monad.IO.Class | |
| -- | |
| -- import Db | |
| -- | |
| -- getUserHandler :: ActionM() | |
| -- getUserHandler = do | |
| -- id <- param "id" | |
| -- user <- liftIO (Db.getUser id) -- liftIO to actionM | |
| -- json user | |
| -- | |
| -- getAllUsersHandler :: ActionM() | |
| -- getAllUsersHandler = do | |
| -- users <- liftIO Db.getAllUsers -- liftIO to actionM | |
| -- json users | |
| -- | |
| -- createRoom :: ActionM() | |
| -- createRoom = do | |
| -- room <- params | |
| -- text (room) | |
| -- | |
| -- getFirstParam :: Param -> String | |
| -- getFirstParam param = (head Param) | |
| -- | |
| -- routes :: ScottyM () | |
| -- routes = do | |
| -- get "/users" getAllUsersHandler | |
| -- get "/users/:id" getUserHandler | |
| -- post "/rooms/create" createRoom | |
| -- | |
| -- main :: IO () | |
| -- main = do | |
| -- putStrLn "Starting Server..." | |
| -- scotty 4888 routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment