NAME

Kelp::Request - Request class for a Kelp application

SYNOPSIS

my $request = Kelp::Request( app => $app, env => $env );

DESCRIPTION

This module provides a convenience layer on top of Plack::Request. It extends it to add several convenience methods.

ATTRIBUTES

app

A reference to the Kelp application.

stash

An all use, utility hash to use to pass information between routes.

named

This hash is initialized with the named placeholders of the path that the current route is processing.

param

Returns the HTTP parameters of the request. This method delegates all the work to "param" in Plack::Request, except when the content type of the request is application/json. In that case, it will decode the JSON body and return as follows:

  • If no arguments are passed, then it will return the names of the HTTP parameters when called in array contest, and a reference to the entire JSON hash when called in scalar context.

    # JSON body = { bar => 1, foo => 2 }
    my @names = $self->param;   # @names = ('bar', 'foo')
    my $json = $self->param;    # $json = { bar => 1, foo => 2 }
  • If a single argument is passed, then the corresponding value in the JSON document is returned.

    my $bar = $self->param('bar');  # $bar = 1

is_ajax

Returns true if the request was called with XMLHttpRequest.

is_json

Returns true if the request's content type was application/json.