Skip to content

Commit

Permalink
docs(recipes): update plain-text-handler.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 authored Dec 30, 2024
1 parent 2c515be commit 039d728
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions docs/user/recipes/plain-text-handler.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
.. _plain-text-recipe:
.. _plain_text_handler_recipe:

Handling Plain Text
===================

.. _custom-text-handler:

Custom Text Media Handler
=========================
Handling Plain Text as Media
============================

This example demonstrates how to create a custom handler in Falcon to
process `text/plain` media type. The handler implements serialization
process the ``text/plain`` media type. The handler implements serialization
and deserialization of textual content, respecting the charset specified
in the `Content-Type` header or defaulting to `utf-8` when no charset is provided.
in the ``Content-Type`` header (or defaulting to ``utf-8`` when no charset is provided).

.. literalinclude:: ../../../examples/recipes/plain_text_main.py
:language: python

To use this handler, register it in the Falcon application's media
options for both requests and responses:
options for both request and response:

.. code:: python
Expand All @@ -29,7 +24,7 @@ options for both requests and responses:
app.resp_options.media_handlers['text/plain'] = TextHandler()
With this setup, the application can handle textual data directly
as `text/plain`, ensuring support for various character encodings as needed.
as ``text/plain``, ensuring support for various character encodings as needed.

.. warning::
Be sure to validate and limit the size of incoming data when
Expand Down

0 comments on commit 039d728

Please sign in to comment.