class Responsible::Response

Overview

Wrapper object for lifted responses. Provides extensions need for defining locally scoped error behaviors and parse tools for extraction of returned data.

Defined in:

responsible/response.cr

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(response : Responsible::ResponseInterface) #

Creates a new Response by wrapping a supported response type. response must by a type that includes ResponsibleInterface. This can be inserted manually, or by using the Responsible.support macro.


[View source]

Instance Method Detail

def >>(x : T.class) : T forall T #

Parses the contents of this response to the type x.

If x is nilable, a parser error will result in nil being returned, otherwise a Responsible::Error will be raised if parsing is not possible.


[View source]
def on_client_error(& : Action) : self #

Execute the passed block if this is a client_error response.


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

Execute the passed block if this is a informational response.


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

Execute the passed block if this is a redirection response.


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

Execute the passed block if this is a server_error response.


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

Execute the passed block if this is a success response.


[View source]
def parse_to(x : T.class, ignore_response_code = @in_handler, & : Exception -> U) : T | U forall T, U #

Reads the contents of the body into the specified type x.

If the response cannot be parsed, the block will be yielded to to provide an alternative parser.

T.from_json must exist and be capable of deserializing a JSON string. This works out-of-the-box for most types where attributes map directly. The JSON::Serializable module provides tools for more complex parsing.


[View source]
def parse_to(x : T.class, ignore_response_code = @in_handler) : T forall T #

Parses the contents of this response to the type x, or raises an Responsible::Error if this is not possible.


[View source]
def parse_to?(x : T.class, ignore_response_code = @in_handler) : T | Nil forall T #

Parses the contents of this response to the type x, or nil if this is not possible.


[View source]

Macro Detail

macro method_missing(call) #

[View source]