About
This is an implementation of JSON RPC 2.0 server (groups.google.com/group/json-rpc/web/json-rpc-2-0?pli=1)
Using
To make your rails controller JSON RPC 2.0 callable, do next
class TestController < ActionController::Base
include JSONServer # adds json-rpc 2.0 functionality
def index
# next will redirect post contents to json-rpc dispatcher
# and output resut as string
render :text => dispatch_json_2(request.body.read)
end
# function which will become remotely callable
def summ(left, right)
return left+right
end
end
In your config/routing.rb you will have to add
post 'json' => 'test#index'
JSONServer will automaticaly check if posted json is valid JSON-RPC 2.0 request and fire called method. if method is not found - propper error will be sent.
Batch request are handled. Notices are handled. Test taken from examples on groups.google.com/group/json-rpc/web/json-rpc-2-0?pli=1
Errors
You can raise standart errors, or JSONRPCError with parameters :code, :message, :data, which will be set for correspoding fields :code defaults to -30000 if JSONServer::Error and to -32000 otherwise :message defaults to “Runtime Error”