RubyGems.org

jsonrpc2

0.0.7

Description

A Rack compatible JSON-RPC2 server domain specific language (DSL) - allows JSONRPC APIs to be defined as mountable Rack applications with inline documentation, authentication and type checking.

e.g.

class Calculator < JSONRPC2::Interface
  title "JSON-RPC2 Calculator"
  introduction "This interface allows basic maths calculations via JSON-RPC2"
  auth_with JSONRPC2::BasicAuth.new({'user' => 'secretword'})

  section 'Simple Ops' do
      desc 'Multiply two numbers'
      param 'a', 'Number', 'a'
      param 'b', 'Number', 'b'
      result 'Number', 'a * b'
      def mul args
        args['a'] * args['b']
      end

      desc 'Add numbers'
      example "Calculate 1 + 1 = 2", :params => { 'a' => 1, 'b' => 1}, :result => 2

      param 'a', 'Number', 'First number'
      param 'b', 'Number', 'Second number'
      optional 'c', 'Number', 'Third number'
      result 'Number', 'a + b + c'
      def sum args
        val = args['a'] + args['b']
        val += args['c'] if args['c']
        val
      end
  end
end
installgem install jsonrpc2 -v 0.0.7
Authors

Geoff Youngs

3,338 total downloads 339 for this version
Owners

132ef4c367de54cc8c5b0f3e0376a33f

Gemfile
gem "jsonrpc2", "~> 0.0.7"
Versions
  1. 0.0.9 September 3, 2012
  2. 0.0.8 September 3, 2012
  3. 0.0.7 August 27, 2012
  4. 0.0.6 August 24, 2012
  5. 0.0.5 July 19, 2012
Show all versions (9 total)