Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/helios-technologies/json-rpc
Json RPC Module for Rack application
https://github.com/helios-technologies/json-rpc
Last synced: 3 months ago
JSON representation
Json RPC Module for Rack application
- Host: GitHub
- URL: https://github.com/helios-technologies/json-rpc
- Owner: helios-technologies
- Created: 2011-06-07T18:48:23.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-07-27T14:11:39.000Z (over 13 years ago)
- Last Synced: 2024-08-09T12:26:28.130Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 142 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-json-rpc - helios-technologies/json-rpc - 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. (Libraries)
README
Json Rpc
========Implementation of [JSON RPC 2.0](http://groups.google.com/group/json-rpc/web/json-rpc-2-0) protocol.
It allows you to create easily json rpc server.Usage
-----Simple Rack example:
~~~~~~ {ruby}
require 'json-rpc'class SyncApp
include JsonRpc
def call env
result = rpc_call(env) { |e|
logger.info "#{e}"
}
result
enddef rpc_sum a, b
a + b
end
end
run SyncApp.new
~~~~~~Asynchronous Event Machine example:
~~~~~~ {ruby}
require 'json-rpc'class AsyncApp
include JsonRpc
AsyncResponse = [-1, {}, []].freeze
def call env
rpc_call(env)
enddef 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:
~~~~~~ {sh}
$ thin -R example.ru -p 4242 -d start
$ curl "http://localhost:4242/rpc?jsonrpc=2.0&method=sum¶ms=%5B21%2C21%5D"
{"jsonrpc":"2.0","id":0,"result":42}
~~~~~~### License
Copyright 2011 [Helios Technologies Ltd.](http://www.heliostech.hk)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 athttp://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.