NotionCommotion Posted January 29, 2018 Share Posted January 29, 2018 I am receiving JSON-RPC method requests, processing it and updating the server state if valid, and either returning a JSON-RPC error response or the results. //$jsonRpc is provided by another machine //Returns ['success'=>true/false, 'rs'=>{error or result}] $output=processResults($jsonRpc); $response=($output['success']==1)? makeResultReponse($output['rs']) :makeErrorReponse($output['rs']); Any recommendations on how best to tag the data as valid or not? For instance: Option 1. Have processResults return ['success'=>true/false, 'rs'=>{error or result}] Option 2. Have processResults return ['result'=>{result}] or ['error'=>{error}] Option 3. Have processResults return [true/false, {error or result}] Option 4. Have processResults return an object which is an instance of the success or error class Option 5. Uses exceptions to indicate that the received data was invalid. Option 6. Something else? Quote Link to comment https://forums.phpfreaks.com/topic/306358-processing-data-and-identifying-whether-valid/ Share on other sites More sharing options...
requinix Posted January 29, 2018 Share Posted January 29, 2018 "result", "success", and "error" are all commonly used (not all at the same time, of course). However if you're following JSON-RPC then you should do what they say: result This member is REQUIRED on success. This member MUST NOT exist if there was an error invoking the method. The value of this member is determined by the method invoked on the Server. error This member is REQUIRED on error. This member MUST NOT exist if there was no error triggered during invocation. The value for this member MUST be an Object as defined in section 5.1. Quote Link to comment https://forums.phpfreaks.com/topic/306358-processing-data-and-identifying-whether-valid/#findComment-1555844 Share on other sites More sharing options...
NotionCommotion Posted January 30, 2018 Author Share Posted January 30, 2018 "result", "success", and "error" are all commonly used (not all at the same time, of course). However if you're following JSON-RPC then you should do what they say: After reading your reply, I re-read my original post, and realize I was not clear. I have implemented per the 2.0 spec for protocol between different machines. Eventually, I get to a single machine which has multiple classes which perform various functions, and I am inquiring only for this scope where I am in control of end-to-end. Often a method will return true/false or a value or an object, etc, and and I will implement as applicable. However, the primary function of the application is dealing with this inter-machine communication and as such, I find myself often dealing with similar data as JSON-RPC. Seems kind of silly to include a jsonrpc:2.0 property in all my internal handshakes, and I feel arrays can cut down on clutter when needing to create structure which later gets turned into JSON and thus object notation. But then again, constancy is rather nice, so maybe in the long run it will be of benefit. Or maybe I was clear. Was your understanding that I was referring only to communication directly within a single application? Quote Link to comment https://forums.phpfreaks.com/topic/306358-processing-data-and-identifying-whether-valid/#findComment-1555864 Share on other sites More sharing options...
Solution requinix Posted January 30, 2018 Solution Share Posted January 30, 2018 So this is for a different part of the application than the RPC messages? Then I'd still follow what the spec says (regarding this particular bit) simply for the consistency - every part of the system uses the same result/error structure so there's no confusion. Quote Link to comment https://forums.phpfreaks.com/topic/306358-processing-data-and-identifying-whether-valid/#findComment-1555865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.