Module: PatientHttp::RequestHelper
- Extended by:
- RequestHelper
- Includes:
- HttpMethodHelpers
- Included in:
- RequestHelper
- Defined in:
- lib/patient_http/request_helper.rb
Overview
Mixin that provides a compact API for scheduling async HTTP requests.
Include this module in your class to get instance-level and class-level helpers for building requests and dispatching them through a registered handler.
This module allows you to use the same interface for making HTTP requests while swapping out the underlying queueing mechanism for handling responses asynchronously. By registering a custom handler, you can integrate with any job queue system (Sidekiq, Solid Queue, etc.) without changing your application code that makes HTTP requests. This decouples your request interface from your async processing infrastructure.
The common workflow is:
-
Register a global request handler with register_handler.
-
Include this module in a class.
-
Optionally configure defaults with request_template.
-
Call ‘async_get`, `async_post`, `async_put`, `async_patch`, `async_delete`, or `async_request`.
Defined Under Namespace
Modules: ClassMethods, HttpMethodHelpers
Class Method Summary collapse
-
.included(base) ⇒ void
Hooks helper behavior into the including class.
Instance Method Summary collapse
-
#async_request(method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil) ⇒ Object
Dispatches an asynchronous HTTP request from an instance context.
Methods included from HttpMethodHelpers
#async_delete, #async_get, #async_patch, #async_post, #async_put
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Hooks helper behavior into the including class.
Extends the class with ClassMethods and initializes template storage.
48 49 50 51 |
# File 'lib/patient_http/request_helper.rb', line 48 def included(base) base.extend(ClassMethods) base.instance_variable_set(:@patient_http_request_template, nil) end |
Instance Method Details
#async_request(method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil) ⇒ Object
Dispatches an asynchronous HTTP request from an instance context.
This delegates to PatientHttp::RequestHelper::ClassMethods#async_request on the including class.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/patient_http/request_helper.rb', line 202 def async_request( method, url, callback:, headers: nil, body: nil, json: nil, params: nil, timeout: nil, raise_error_responses: nil, callback_args: nil ) self.class.async_request( method, url, callback: callback, headers: headers, body: body, json: json, params: params, timeout: timeout, raise_error_responses: raise_error_responses, callback_args: callback_args ) end |