Skip to content

Instantly share code, notes, and snippets.

@cschneid
Last active August 29, 2015 14:15
Show Gist options
  • Save cschneid/d43c02e130da071c151a to your computer and use it in GitHub Desktop.
Save cschneid/d43c02e130da071c151a to your computer and use it in GitHub Desktop.
{-# 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