module Responsible
Overview
Base module for top level macros and utilities.
Defined in:
responsible.crresponsible/action.cr
responsible/error.cr
responsible/response_interface.cr
responsible/response_type.cr
Constant Summary
-
HANDLERS =
{} of ResponseType => Action
Class Method Summary
-
.on_client_error(&block : Action) : Nil
Registers an
Action
to execute every on every ClientError response. -
.on_informational(&block : Action) : Nil
Registers an
Action
to execute every on every Informational response. -
.on_redirection(&block : Action) : Nil
Registers an
Action
to execute every on every Redirection response. -
.on_server_error(&block : Action) : Nil
Registers an
Action
to execute every on every ServerError response. -
.on_success(&block : Action) : Nil
Registers an
Action
to execute every on every Success response.
Macro Summary
-
parse_to(type, ignore_response_code = false, &block)
Wraps a expression that returns a supported response object into a
Responsible::Response
and attempts to parse this into the specified type. -
parse_to?(type, ignore_response_code = false, &block)
Wraps a expression that returns a supported response object into a
Responsible::Response
and parse this into the specified type, or nil if not compatible. -
parse_to_return_type(ignore_response_code = false, &block)
Wraps a expression that returns a supported response object into a
Responsible::Response
before attempting to parse this out into the return type of the surrounding method. -
support(response_type, &block)
Adds Responsible support to the specified response type object.
Class Method Detail
Registers an Action
to execute every on every ClientError response.
Registers an Action
to execute every on every Informational response.
Registers an Action
to execute every on every Redirection response.
Registers an Action
to execute every on every ServerError response.
Registers an Action
to execute every on every Success response.
Macro Detail
Wraps a expression that returns a supported response object into a
Responsible::Response
and attempts to parse this into the specified type.
Wraps a expression that returns a supported response object into a
Responsible::Response
and parse this into the specified type, or nil if
not compatible.
Wraps a expression that returns a supported response object into a
Responsible::Response
before attempting to parse this out into the return
type of the surrounding method.
This may be used to provied a clean, minimal syntax when building methods that abstract over API calls.
def example_request : {response_field_a: String, response_field_b: Bool}
Responsible.parse_to_return_type do
HTTP::Client.get "https://www.example.com"
end
end
Adds Responsible support to the specified response type object.
ResponsibleInterface contains a minimal set of abstract methods that are compatible with
HTTP::Client::Response` as well as many third-party
libraries without modification. If you do need to specify an implimentation
to map to other types, an option block may be used to specify the required
implementations.