Allows for the creation of rpc server/client pairs from monomorphic functions. The server portion is a function from a json-encoded list of parameters to a json response. A list of server functions are expected to be wrapped by a dispatch function in the server framework of your choice.
portion generated from a function of arity n is a function from a
string identifying a server or a subdirectory on a server to an arity
expression. This expression, when evaluated on the client side, will
call back to the provided server with json-serialized arguments and yield
the result (deserialized from json). This client function is expected to be embedded
via antiquotation into a larger block of jmacro code.
Client portions must unfortunately be given explicit type signatures.
The following example is a server/client pair providing an ajax call to add integers.
testRPCCall :: String -> JExpr -> JExpr -> JExpr (testRPC, testRPCCall) = mkWebRPC "test" $ \x y -> asIO $ return (x + (y::Int))
This code uses a simple request/response type based on strings to be as agnostic as possible about choice of web service stack. It can be used as is, or used as a model for code which targets a particular web stack (Happstack, Snap, FastCGI, etc.).
- mkWebRPC :: (ToWebRPC a, CallWebRPC a b) => String -> a -> (WebRPCDesc, String -> b)
- asIO :: IO a -> IO a
- type Request = String
- data Response
- type WebRPCDesc = (String, Request -> IO Response)
- class CallWebRPC a b | a -> b where
- class ToWebRPC a where
Produce a pair of (ServerFunction, ClientFunction) from a function in IO
A String containing a json representation of function arguments encoded as a list of parameters. Generally would be passed as part of an HTTP request.
Either a success or failure (with code). Generally would be turned back into a proper HTTP response.