The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Dancer::Request - Interface for accessing incoming requests

DESCRIPTION

This class implements a common interface for accessing incoming requests in a Dancer application.

In a route handler, the current request object can be accessed by the request method, like in the following example:

    get '/foo' => sub {
        request->params; # request, params parsed as a hash ref
        request->body; # returns the request body, unparsed
        request->path; # the path requested by the client
        # ...
    };

A route handler should not read the environment by itslef, but should instead use the current request object.

PUBLIC INTERFACE

method()

Return the HTTP method used by the client to access the application.

path()

Return the path requested by the client.

base()

Returns an absolute URI for the base of the application

uri_for(path, params)

Constructs a URI from the base and the passed path. If params (hashref) is supplied, these are added to the query string of the uri. If the base is http://localhost:5000/foo, request->uri_for('/bar', { baz => 'baz' }) would return http://localhost:5000/foo/bar?baz=baz.

params($source)

If no source given, return a mixed hashref containing all the parameters that have been parsed. Be aware it's a mixed structure, so if you use multiple variables with the same name in your route pattern, query string or request body, you can't know for sure which value you'll get there.

If you need to use the same name for different sources of input, use the $source option, like the following:

If source equals route, then only params parsed from route pattern are returned.

If source equals query, then only params parsed from the query string are returned.

If source equals body, then only params sent in the request body will be returned.

If another value is given for $source, then an exception is triggered.

content_type()

Return the content type of the request.

content_length()

Return the content length of the request.

body()

Return the raw body of the request, unparsed.

If you need to access the body of the request, you have to use this accessor and should not try to read psgi.input by hand. Dancer::Request already did it for you and kept the raw body untouched in there.

is_ajax()

Return true if the value of the header X-Requested-With is XMLHttpRequest.

env()

Return the current environment (%ENV), as a hashref.

uploads()

Returns a reference to a hash containing uploads. Values can be either a Dancer::Request::Upload object, or an arrayref of Dancer::Request::Upload objects.

HTTP environment variables

All HTTP environment variables that are in %ENV will be provided in the Dancer::Request object through specific accessors, here are those supported:

user_agent
host
accept_language
accept_charset
accept_encoding
keep_alive
connection
accept

AUTHORS

This module has been written by Alexis Sukrieh and was mostly inspired by Plack::Request, written by Tatsuiko Miyagawa.

Tatsuiko Miyagawa also gave a hand for the PSGI interface.

LICENCE

This module is released under the same terms as Perl itself.

SEE ALSO

Dancer