Last active
August 29, 2015 14:15
-
-
Save cschneid/d43c02e130da071c151a 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 DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
module Main where | |
import Business.Types | |
import Data.IORef | |
import Servant.API | |
import Servant.Server | |
import Network.Wai.Handler.Warp | |
import Control.Monad.Trans (liftIO) | |
import Control.Monad (void) | |
import Data.Proxy | |
type MyAPI = "counter" :> Get Counter | |
:<|> "counter" :> Post Counter | |
main = do | |
counter <- newIORef (Counter 0) | |
run 7000 $ serve myAPI (server counter) | |
where myAPI :: Proxy MyAPI | |
myAPI = Proxy | |
server :: IORef Counter -> Server MyAPI | |
server ref = getCounter :<|> postCounter | |
where | |
getCounter = liftIO $ readIORef ref | |
postCounter = liftIO $ atomicModifyIORef ref | |
(\c -> (incrementCounter c, | |
incrementCounter c)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment