Dancer2

 view release on metacpan or  search on metacpan

lib/Dancer2/Manual/Keywords.pod  view on Meta::CPAN

    };

B<When to use>: To handle file uploads from client requests.

B<Related Keywords>: L</uploads>, L</request>

=head1 Response Handling Keywords

=head2 L<content|Dancer2::Manual/"content">

Sets the content of the response. This B<only> works within a delayed
response.

This will crash:

    get '/' => sub {
        content 'Hello, world!';
    };

But this will work just fine:

    get '/' => sub {
        delayed {
            content 'Hello, world!';
        };
    };

B<When to use>: Directly set content of an asynchronous response.

B<Related Keywords>: L</response>

=head2 L<content_type|Dancer2::Manual/"Manually Adjusting MIME Settings">

Sets the C<Content-Type> header of the response.

B<When to use>: Specify the MIME type of the response.

B<Related Keywords>: L</header>

=head2 L<decode_json|Dancer2::Manual/decode_json>

Deserializes a JSON string to a Perl data structure. Does not trigger
serialization hooks.

B<When to use>: When you need to translate incoming JSON to a Perl hashref.

B<Related Keywords>: L</encode_json>, L</from_json>

=head2 L<delayed|Dancer2::Manual/delayed>

Initiates an asynchronous response. Requires a Plack/PSGI server capable
of serving requests asynchronously.

B<When to use>: When starting an asynchronous reponse.

B<Related Keywords>: L</done>, L</flush>

=head2 L<done|Dancer2::Manual/done>

Finalizes an asynchronous repsonse and closes the connection. Can only
be run within the streaming response callback.

B<When to use>: When finishing delivery of data asynchronously.

B<See also>: L</delayed>, L</flush>

=head2 L<encode_json|Dancer2::Manual/encode_json>

Serializes a data structure to a UTF-8 encoded binary JSON string. Calling
this keyword will not trigger the application's serializer hooks.

B<When to use>: When needing to translate a Perl data structure to JSON.

B<See also>: L</decode_json>, L</to_json>

=head2 L<flush|Dancer2::Manual/flush>

Flushes content headers when streaming a response. This is necessary when
C<content> is called multiple times.

B<When to use>: When streaming large amounts of data (such as video)
asynchronously.

B<See also>: L</delayed>, L</done>

=head2 L<forward|Dancer2::Manual/forward>

Forwards the request to another route handler.

B<When to use>: Internally redirect to another route within the app.

B<Related Keywords>: L</pass>

=head2 L<from_dumper|Dancer2::Manual/from_dumper>

Deserializes a L<Data::Dumper> structure.

B<When to use>: When you need to turn a L<Data::Dumper> structure into a
Perl hashref.

B<See also>: L</to_dumper>, L</from_json>

=head2 L<from_json|Dancer2::Manual/from_json>

Deserializes a JSON string into a Perl data structure. The input is expected
to be UTF-8 encoded bytes.

B<When to use>: Decode JSON data from the client. L</decode_json> is likely
what you want.

B<Related Keywords>: L</to_json>

=head2 L<from_yaml|Dancer2::Manual/from_yaml>

Deserializes a YAML structure.

B<When to use>: When you need to turn YAML into a Perl hashref.

B<See also>: L</to_yaml>, L</from_json>

=head2 L<halt|Dancer2::Manual/halt>

Halts request processing and sends a response immediately.

B<When to use>: Stop processing and return a response early.

B<Best Practice>: Combine L</halt> with L</status> to ensure appropriate
HTTP response codes are sent.

B<Related Keywords>: L</status>, L</send_error>

=head2 C<header>

Deprecated. Use L</response_header> instead.

B<Related Keywords>: L</response_header>.

=head2 C<headers>

Deprecated. Use L</response_headers> instead.



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