module Responsible

Overview

Base module for top level macros and utilities.

Defined in:

responsible.cr
responsible/action.cr
responsible/error.cr
responsible/response_interface.cr
responsible/response_type.cr

Constant Summary

HANDLERS = {} of ResponseType => Action

Class Method Summary

Macro Summary

Class Method Detail

def self.on_client_error(&block : Action) : Nil #

Registers an Action to execute every on every ClientError response.


[View source]
def self.on_informational(&block : Action) : Nil #

Registers an Action to execute every on every Informational response.


[View source]
def self.on_redirection(&block : Action) : Nil #

Registers an Action to execute every on every Redirection response.


[View source]
def self.on_server_error(&block : Action) : Nil #

Registers an Action to execute every on every ServerError response.


[View source]
def self.on_success(&block : Action) : Nil #

Registers an Action to execute every on every Success response.


[View source]

Macro Detail

macro 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.


[View source]
macro 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.


[View source]
macro 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.

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

[View source]
macro support(response_type, &block) #

Adds Responsible support to the specified response type object.

ResponsibleInterface contains a minimal set of abstract methods that are compatible withHTTP::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.


[View source]