<commit_before>.. _arguments:
.. module:: flask_rest_api

Arguments
=========

To inject arguments into a view function, use the :meth:`Blueprint.arguments
<Blueprint.arguments>` decorator. It allows to specify a :class:`Schema
<marshmallow.Schema>` to deserialize and validate the parameters.

It uses webargs's :meth:`use_args <webargs.core.Parser.use_args>` decorator
internally.

When processing a request, the input data is deserialized, validated, and
injected in the view function.

.. code-block:: python
    :emphasize-lines: 4,6,9,11

    @blp.route('/')
    class Pets(MethodView):

        @blp.arguments(PetQueryArgsSchema, location='query')
        @blp.response(PetSchema(many=True))
        def get(self, args):
            return Pet.get(filters=args)

        @blp.arguments(PetSchema)
        @blp.response(PetSchema, code=201)
        def post(self, pet_data):
            return Pet.create(**pet_data)

Arguments Location
------------------

The list of available locations is available in `webargs documentation 
<https://webargs.readthedocs.io/en/latest/quickstart.html#request-locations>`_.
The location defaults to ``'json'``, which means `body` parameter.

.. note:: Unlike webargs's :meth:`use_args <webargs.core.Parser.use_args>`
   decorator, :meth:`Blueprint.arguments <Blueprint.arguments>` only accepts a
   single location.
<commit_msg>Docs: clarify "location" parameter in arguments<commit_after>.. _arguments:
.. module:: flask_rest_api

Arguments
=========

To inject arguments into a view function, use the :meth:`Blueprint.arguments
<Blueprint.arguments>` decorator. It allows to specify a :class:`Schema
<marshmallow.Schema>` to deserialize and validate the parameters.

When processing a request, the input data is deserialized, validated, and
injected in the view function.

.. code-block:: python
    :emphasize-lines: 4,6,9,11

    @blp.route('/')
    class Pets(MethodView):

        @blp.arguments(PetQueryArgsSchema, location='query')
        @blp.response(PetSchema(many=True))
        def get(self, args):
            return Pet.get(filters=args)

        @blp.arguments(PetSchema)
        @blp.response(PetSchema, code=201)
        def post(self, pet_data):
            return Pet.create(**pet_data)

Arguments Location
------------------

The following locations are allowed:

    - ``"json"``
    - ``"query"`` (or ``"querystring"``)
    - ``"path"``
    - ``"form"``
    - ``"headers"``
    - ``"cookies"``
    - ``"files"``

The location defaults to ``"json"``, which means `body` parameter.

.. note:: :meth:`Blueprint.arguments <Blueprint.arguments>` uses webargs's
   :meth:`use_args <webargs.core.Parser.use_args>` decorator internally, but   
   unlike :meth:`use_args <webargs.core.Parser.use_args>`, it only accepts a
   single location.

{'fraction_non_alphanumeric': 0.14653323802716225, 'fraction_numerical': 0.005718370264474625, 'mean_word_length': 3.6112026359143328, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2802873', 'n_tokens_mistral': 886, 'n_tokens_neox': 839, 'n_words': 229}