Apache2::REST::Response - Container for an API Response.


Apache2-REST documentation Contained in the Apache2-REST distribution.

Index


Code Index:

NAME

Top

Apache2::REST::Response - Container for an API Response.

SYNOPSIS

 ... 
 $resp->status(Apache2::Const::HTTP_OK) ;
 $resp->message('Everything went smootly') ;
 $resp->data()->{'item'} = 'This is the returned item' ;
 ...

new

Builds a new one.

cleanup

Cleanup this response so it can go out without any empty attributes.

Internal use.

status

Get/Sets the HTTP status of this response

message

Get/Sets a more explicit message related to the status

data

Hash of the actual data returned by the handler (see Apache2::REST::Handler ).

bin

Get/Set the binary content to return in case the bin writer is used.

binMimeType

Get/Set the MIME type of the binary content.

stream

Get/Set the Apache2::REST::Stream to render this response as a stream of data.

Setting this will trigger a '_Stream' version of writers to be used.

multipart_stream

Get/Set the Apache2::REST::Stream to render this response as a stream of data composed of multipart response parts.

Setting this will trigger a '_multipart' version of writers to be used.


Apache2-REST documentation Contained in the Apache2-REST distribution.
package Apache2::REST::Response ;

use strict ;
use warnings ;

use base qw/Class::AutoAccess/ ;

use Apache2::Const qw( 
                       :common :http 
                       );


sub new{
    my ( $class ) = @_ ;
    
    my $self = {
        'status' => Apache2::Const::HTTP_OK ,
        'message' => '' ,
        'data' => {},
        'binMimeType' => undef ,
        'bin' => undef ,
	'stream' => undef,
	'multipart_stream' => undef,
    };
    return bless $self , $class ;
}

sub cleanup{
    my ( $self ) = @_ ;
    foreach my $key ( keys %$self ){
        unless( defined $self->{$key} ){
            delete $self->{$key} ;
        }
    }
    
}

1;