-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | JSON-RPC 2.0 on the server side.
--   
--   An implementation of the server side of JSON-RPC 2.0. See
--   <a>http://www.jsonrpc.org/specification</a>. This library uses
--   <a>ByteString</a> for input and output, leaving the choice of
--   transport up to the user. See the <a>Network.JsonRpc.Server</a> module
--   for an example. json-rpc-server can be used with
--   <a>json-rpc-client</a> to create a client and server that communicate
--   with the same methods.
@package json-rpc-server
@version 0.2.6.0


-- | Functions for implementing the server side of JSON-RPC 2.0. See
--   <a>http://www.jsonrpc.org/specification</a>.
module Network.JsonRpc.Server

-- | Return type of a method. A method call can either fail with an
--   <a>RpcError</a> or succeed with a result of type <tt>r</tt>.
type RpcResult m r = ExceptT RpcError m r

-- | A JSON-RPC method.
data Method m

-- | Creates a method from a name, function, and parameter descriptions.
--   The parameter names must be unique.
toMethod :: (MethodParams f p m r) => Text -> f -> p -> Method m

-- | Handles one JSON-RPC request. It is the same as
--   <tt>callWithBatchStrategy sequence</tt>.
call :: Monad m => [Method m] -> ByteString -> m (Maybe ByteString)

-- | Handles one JSON-RPC request. The method names must be unique.
callWithBatchStrategy :: Monad m => (forall a. NFData a => [m a] -> m [a]) -> [Method m] -> ByteString -> m (Maybe ByteString)

-- | Parameter expected by a method.
data Parameter a

-- | Required parameter with a name.
Required :: Text -> Parameter a

-- | Optional parameter with a name and default value.
Optional :: Text -> a -> Parameter a

-- | A node in a type-level linked list of <a>Parameter</a> types. It is
--   right associative.
data a (:+:) ps
(:+:) :: (Parameter a) -> ps -> (:+:) a ps

-- | Relationship between a method's function (<tt>f</tt>), parameters
--   (<tt>p</tt>), monad (<tt>m</tt>), and return type (<tt>r</tt>).
--   <tt>p</tt> has one <a>Parameter</a> for every argument of <tt>f</tt>
--   and is terminated by <tt>()</tt>. The return type of <tt>f</tt> is
--   <tt>RpcResult m r</tt>. This class is treated as closed.
class (Monad m, ToJSON r) => MethodParams f p m r | f -> p m r, p m r -> f

-- | JSON-RPC error.
data RpcError
RpcError :: Int -> Text -> Maybe Value -> RpcError
[errCode] :: RpcError -> Int
[errMsg] :: RpcError -> Text
[errData] :: RpcError -> Maybe Value

-- | Creates an <a>RpcError</a> with the given error code and message.
--   According to the specification, server error codes should be in the
--   range -32099 to -32000, and application defined errors should be
--   outside the range -32768 to -32000.
rpcError :: Int -> Text -> RpcError

-- | Creates an <a>RpcError</a> with the given code, message, and
--   additional data. See <a>rpcError</a> for the recommended error code
--   ranges.
rpcErrorWithData :: ToJSON a => Int -> Text -> a -> RpcError

-- | <i>Deprecated: Use [<a>Method</a> m].</i>
type Methods m = [Method m]

-- | <i>Deprecated: Use <a>call</a> directly.</i>
toMethods :: [Method m] -> Methods m
