From 403170fbb428ece7d202c661b1868a95531ec595 Mon Sep 17 00:00:00 2001 From: Kurt Griffiths Date: Mon, 8 May 2017 08:55:45 -0600 Subject: [PATCH] doc(FAQ): How to access form params (#1045) --- docs/user/faq.rst | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/user/faq.rst b/docs/user/faq.rst index 8c678eb..0e03cc4 100644 --- a/docs/user/faq.rst +++ b/docs/user/faq.rst @@ -176,7 +176,20 @@ attribute. For example: api.req_options.keep_blank_qs_values = True +How can I access POSTed form params? +------------------------------------ +By default, Falcon does not consume request bodies. However, setting +the :attr:`~RequestOptions.auto_parse_form_urlencoded` to ``True`` +will cause the framework to consume the request body when the +content type is `application/x-www-form-urlencoded`, making +the form parameters accessible via :attr:`~.Request.params`, +:meth:`~.Request.get_param`, etc. -.. If Falcon is designed for building web APIs, why does it support forms? -.. ---- -.. Doesn't support files, allows same code to handle both... +.. code:: python + + api.req_options.auto_parse_form_urlencoded = True + +Alternatively, POSTed form parameters may be read directly from +:attr:`~.Request.stream` and parsed via +:meth:`falcon.uri.parse_query_string` or +`urllib.parse.parse_qs() `_.