Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.01 KB

README.md

File metadata and controls

39 lines (29 loc) · 1.01 KB

Build Status

haskell-msgpackrpc

MsgPack RPC implementation for Haskell (server side only, for now)

Example

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
import           BasicPrelude              hiding (catch, finally, try)

import           Control.Monad.Catch
import qualified Data.Map                  as Map

import           Network.MsgpackRpc.Server


default (Text)

-- This sums arguments
sumMethod :: Int -> Int -> RpcMethodT IO Int
sumMethod a b = return $! a + b

-- This throws error to client
errorMethod :: RpcMethodT IO Int
errorMethod = throwM $ rpcError ".MyRpc.SomeCoolError" ("WAT!?" :: Text)

func :: IO ()
func = do
    let methodMap =  Map.fromList
            [
              ("sum", rpcMethod sumMethod)
            , ("error", rpcMethod errorMethod)
            ]
    serveRpc 128 (serverSettings 5252 "*") methodMap

main :: IO ()
main = func