class Amber::Schema::ResponseBuilder

Defined in:

amber/schema/response_builder.cr

Constructors

Instance Method Summary

Constructor Detail

def self.error(message : String, code : String = "error") : ResponseBuilder #

[View source]
def self.forbidden(message : String = "Forbidden") : ResponseBuilder #

[View source]
def self.from_result(result : LegacyResult) : ResponseBuilder #

Build response from a validation result


[View source]
def self.new(status : Status = Status::Success) #

[View source]
def self.not_found(resource : String | Nil = nil) : ResponseBuilder #

[View source]
def self.success(data : Hash(String, JSON::Any) | Nil = nil) : ResponseBuilder #

Factory methods for common responses


[View source]
def self.unauthorized(message : String = "Unauthorized") : ResponseBuilder #

[View source]
def self.validation_error(errors : Array(Error)) : ResponseBuilder #

[View source]

Instance Method Detail

def add_error(error : Error) #

[View source]
def add_metadata(key : String, value : JSON::Any) #

[View source]
def add_warning(warning : Warning) #

[View source]
def build(format : Format = Format::JSON) : Hash(String, JSON::Any) #

Build the response


[View source]
def data : Hash(String, JSON::Any) | Nil #

[View source]
def data=(data : Hash(String, JSON::Any) | Nil) #

Setters with method chaining


[View source]
def errors : Array(Error) #

[View source]
def http_status : Int32 #

HTTP status code based on response status


[View source]
def metadata : Hash(String, JSON::Any) #

[View source]
def paginate(page : Int32, per_page : Int32, total : Int32) #

Set pagination metadata


[View source]
def status : Status #

[View source]
def to_json(format : Format = Format::JSON) : String #

Convert to JSON string


[View source]
def warnings : Array(Warning) #

[View source]