By accident I have recently found a JSON-RPC protocol and discovered that I have almost "reinvented" it in one of our side projects. So I have decided to write a client/server implementation from scratch based on json-rpc 2.0 specification. Sources and additional information are available at http://github.com/xored/jsonrpc. And below is a short, but fully functional example on using it.
On server side:
using util
using jsonrpc
class Server : AbstractMain
{
@Opt Int port := 8080
override Int run()
{
runServices([
WispService
{
it.port = this.port
it.root = RpcMod(MathHandler())
}
])
}
}
** All methods from this class will be available to clients
const class MathHandler : ReflectHandler
{
Int sum(Int[] args) { args.reduce(0) |Int r, Int v->Int| { r + v } }
}
And the client side:
using jsonrpc
class Client
{
static Void main()
{
//prints 6
echo(RpcWebClient(`http://localhost:8080`).request("sum", [[1,2,3]])
}
}
Comments and pull requests are welcome :)
DanielFathTue 18 Sep 2012
That looks really cool. Sadly I don't have git installed, yet. I can definitely can see this being useful for server like tales, etc.
ivan Tue 18 Sep 2012
By accident I have recently found a JSON-RPC protocol and discovered that I have almost "reinvented" it in one of our side projects. So I have decided to write a client/server implementation from scratch based on json-rpc 2.0 specification. Sources and additional information are available at http://github.com/xored/jsonrpc. And below is a short, but fully functional example on using it.
On server side:
And the client side:
Comments and pull requests are welcome :)
DanielFath Tue 18 Sep 2012
That looks really cool. Sadly I don't have git installed, yet. I can definitely can see this being useful for server like tales, etc.
andy Thu 20 Sep 2012
Cool stuff.