
Apologize in advance for the English language. I'm working with json-rpc interface (http://json-rpc.org/) via http. Requests and responses look like this: -> {"jsonrpc" : "2.0", "id" : "1", "method" : "user.authenticate", "params" : { "user" : "myUser", "password" : "myPassword" }} <- {"jsonrpc":"2.0","result":"97d4b59d2f2fbf703bb7aa257aae5254","id":"1"} -> {"jsonrpc" : "2.0", "id" : "2", "method" : "user.getObjects", "auth" : "97d4b59d2f2fbf703bb7aa257aae5254", "params" : { "alias" : "myUser" }} <- {"jsonrpc":"2.0","result":[{"userid":"3","alias":"myUser","name":"lala", "surname":"lala","passwd":"c5aba41f671a02a3c8a6f10a2a7d8a19", "url":"myUrl","autologin":"1","autologout":"0","lang":"ru_ru", "refresh":"30","type":"1","theme":"css_bb.css","attempt_failed":"0", "attempt_ip":"0.0.0.0","attempt_clock":"1282502966", "rows_per_page":"50"}],"id":"2"} How can i describe in Haskell my task? P.S. The first request is required for authentication (field "auth" in the following queries). Using the second query, I want to know "userid"). P.P.S. My first approach is to describe rpc query as following: data RpcQuery = RpcQuery { rpcVersion :: String, rpcId :: String, rpcMethod :: String, rpcAuth :: String, rpcParams :: AuthUser } deriving (Show) data AuthUser = AuthUser { authUser :: String, authPassword :: String } deriving (Show) instance JSON AuthUser where showJSON au = makeObj [ ("user", showJSON $ authUser au) , ("password", showJSON $ authPassword au) ] readJSON (JSObject obj) = let jsonObjAssoc = fromJSObject obj in do user <- mLookup "user" jsonObjAssoc >>= readJSON password <- mLookup "password" jsonObjAssoc >>= readJSON return $ AuthUser { authUser = user , authPassword = password } readJSON _ = fail "" But this scheme is not extended.