FU

 view release on metacpan or  search on metacpan

FU.pm  view on Meta::CPAN


Upper-case request method, e.g. 'POST' or 'GET'.

=item fu->header($name)

Return the request header by the given C<$name>, or undef if the requests did
not have that header. Header name matching is case-insensitive. If the request
includes multiple headers with the same name, these are merged into a single
comma-separated value.

=item fu->headers

Return a hashref with all request headers. Keys are lower-cased header names.

=item fu->ip

Return the client IP address.

=item fu->query()

Return the raw query part of the request URI, e.g.
C<https://example.com/some/path?query> this returns C<query>.

=item fu->query($name)

Parses the raw query string with C<query_decode> in L<FU::Util> and returns the
value with the given $name. Beware: an array is returned if the given key is
repeated in the query string.  Prefer to use the C<$schema>-based validation
methods below to reliably handle all sorts of query strings.

=item fu->query($name => $schema)

Parse, validate and return the query parameter identified by C<$name> with the
given L<FU::Validate> schema.

To fetch a query parameter that may have multiple values, use:

  my $arrayref = fu->query(q => {accept_scalar => 1});

  # OR:
  my $first_value = fu->query(q => {accept_array => 'first'});

  # OR:
  my $last_value = fu->query(q => {accept_array => 'last'});

=item fu->query($schema)

=item fu->query($name1 => $schema1, $name2 => $schema2, ..)

Parse, validate and return multiple query parameters.

  state $schema = FU::Validate->compile({
      keys => { a => {anybool => 1}, b => {} }
  });
  my $data = fu->query($schema);
  # $data = { a => .., b => .. }

  # Or, more concisely:
  my $data = fu->query(a => {anybool => 1}, b => {});

To fetch all query paramaters as decoded by C<query_decode()>, use:

  my $data = fu->query({type=>'any'});

=item fu->cookie(...)

Like C<< fu->query() >> but parses the C<Cookie> request header. Beware that,
exactly like with query parameters, it's possible for a cookie to have multiple
values and thus get represented as an array.

=item fu->json(...)

Like C<< fu->query() >> but parses the request body as JSON. Returns the raw
(unvalidated!) JSON Unicode string if no arguments are given. To retrieve the
decoded JSON data without performing further validation, use:

  my $data = fu->json({type=>'any'});

=item fu->formdata(...)

Like C<< fu->query() >> but returns data from the POST request body. This
method only supports form data encoded as C<application/x-www-form-urlencoded>,
which is the default for HTML C<< <form> >>s. To handle multipart form data,
use C<< fu->multipart >> instead.

=item fu->multipart

Parse the request body as C<multipart/form-data> and return an array of field
objects.  Refer to L<FU::MultipartFormData> for more information.

=back


=head1 Response Generation

=over

=item fu->done

Throw an exception to indicate that the response is "done", i.e. the current
function will return and no further handlers (if any) are run. Only works if
you're not catching the exception elsewhere, of course.

=item fu->error($code, $message)

Throw an exception with a status code. If the exception is not caught
elsewhere, this ends up in running the appropriate C<FU::on_error> handler.

C<$message> is optional and currently only used for logging.

=item fu->denied

Alias for C<< fu->error(403) >>.

=item fu->notfound

Alias for C<< fu->error(404) >>.

=item fu->reset

Reset the response to an empty state, basically undoing all effects of the
methods below.

=item fu->status($code)

Set the HTTP status code for the response. Defaults to C<200> if not set and no
error is thrown.

=item fu->add_header($name, $value)

Add a response header, can be used to add multiple headers with the same name.

=item fu->set_header($name, $value)

Add a response header or overwrite the header with a new value if it already



( run in 1.462 second using v1.01-cache-2.11-cpan-39bf76dae61 )