Class: JSONRPC::Middleware
- Inherits:
-
Object
- Object
- JSONRPC::Middleware
- Defined in:
- lib/jsonrpc/middleware.rb
Overview
Rack middleware for handling JSON-RPC 2.0 requests
This middleware intercepts HTTP POST requests at a specified path and processes them as JSON-RPC 2.0 messages. It handles parsing, validation, and error responses according to the JSON-RPC 2.0 specification.
Constant Summary collapse
- DEFAULT_PATH =
Default path for JSON-RPC requests
'/'
Instance Method Summary collapse
-
#call(env) ⇒ Array
Rack application call method.
-
#initialize(app, options = {}) ⇒ Middleware
constructor
Initializes the JSON-RPC middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Initializes the JSON-RPC middleware
45 46 47 48 49 50 51 52 53 |
# File 'lib/jsonrpc/middleware.rb', line 45 def initialize(app, = {}) @app = app @parser = Parser.new @validator = Validator.new @path = .fetch(:path, DEFAULT_PATH) @config = JSONRPC.configuration @log_internal_errors = .fetch(:log_internal_errors, @config.log_internal_errors) @rescue_internal_errors = .fetch(:rescue_internal_errors, @config.rescue_internal_errors) end |
Instance Method Details
#call(env) ⇒ Array
Rack application call method
66 67 68 69 70 71 72 73 74 |
# File 'lib/jsonrpc/middleware.rb', line 66 def call(env) @req = Rack::Request.new(env) if jsonrpc_request? handle_jsonrpc_request else @app.call(env) end end |