Using JSON

Is there a sample anywhere that shows how to connect to a custom web api using JSON? We are developing something that the web application will provide an api to me, using JSON, but I’m a little unclear on how to make the interface part for my RO client, which is created in Delphi XE2.

Thanks
Jeremy

Are we talking about json-rpc service or something else? Could you post some request/response examples of that custom api?

I want to POST parameters to the API (just a http post), something like:

“Action” = e.g “ResetPassword”
“UserID” = “The user index from the user table”

I would be looking for the Result parameter in the JSON. If success it would say “success” otherwise I would also have a paramater called “errors” which describes the problem. I can’t show the exact API as it’s only open to specific IP, but I might get something like this in the browser:

{“Result”:“failed”,“ErrorCode”:1,“ErrorText”:“No Action Specified”}

I was thinking it was just like accessing a SOAP server, which I’ve done before with RO SDK easily as it imports the WSDL and just works, so I guess I’m asking how to send the correct parameters for different API functions.

Thanks

I’m afraid this can’t be done so easily. To ‘just use’ JSONMessage, API should implement json-rpc and process requests like
{“method”:“ResetPassword”, “params”:{“UserID”:“3”}}
and return something like (may be not real json-rpc, just mocking up)
{“version”:“1.1”,“result”:{“Result”:“failed”, “ErrorCode”:1,“ErrorText”:“No Action Specified”}}
or
{“version”:“1.1”,“result”:{“Result”:“success”}}

Thanks. So, the web developer can do the json-rpc service so back to my original question, is there an example anywhere I can look at to see how to do this?

Basically, there is no difference between website exposing json-rpc service and regular RO server that uses JSONMessage. So you’ll need to manually describe the service in the Service Builder (like add method ‘ResetPassword’ that takes string parameter ‘UserID’ and return string result)

Btw, you could start with implementing MegaDemoService.Sum method at the server and using Mega Demo Client as a test app.

Thanks, I was thinking I could just create a dummy server, just to get the interface file for my client. I’ll try that.