Project

json-rpc

0.01
No commit activity in last 3 years
No release in over 3 years
Implementation of JSON RPC 2.0 protocol. It allows you to create easily a json rpc server in pure Rack, in Rails, or asynchronous using Thin and EventMachine.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Json Rpc

Implementation of JSON RPC 2.0 protocol. It allows you to create easily json rpc server.

Usage

Simple Rack example:

require 'json-rpc'

class SyncApp
  include JsonRpc
  def call env
    result = rpc_call(env) { |e|
      logger.info "#{e}"
    }
    result
  end

  def rpc_sum a, b
    a + b
  end
end
run SyncApp.new

Asynchronous Event Machine example:

require 'json-rpc'

class AsyncApp
  include JsonRpc
  AsyncResponse = [-1, {}, []].freeze
  def call env
    rpc_call(env)
  end

  def rpc_sum a, b
    result = Rpc::AsyncResult.new
    EventMachine::next_tick do
      result.reply a + b
      result.succeed
    end
    result
  end
end

Test it works:

$ thin -R example.ru -p 4242 -d start
$ curl "http://localhost:4242/rpc?jsonrpc=2.0&method=sum&params=%5B21%2C21%5D"
{"jsonrpc":"2.0","id":0,"result":42}

License

Copyright 2011 Helios Technologies Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.