This rule raises an issue when a Flask route handles POST requests and accesses query parameters using request.args.

Why is this an issue?

Using query parameters in POST requests violates REST principles and creates poorly designed APIs.

In RESTful design, POST requests should use:

Query parameters in POST requests have several problems:

For example, using POST /resource?key=listOfUsers/user1 exposes the internal XPath structure. This tight coupling between the URL and internal data structure makes the API fragile and harder to maintain.

Proper RESTful design keeps resource identification in the path and data in the body, creating cleaner, more maintainable APIs.

What is the potential impact?

This design flaw can lead to:

How to fix it

Use path parameters for resource identification and request body for data. Replace query parameters with proper RESTful URL design.

Code examples

Noncompliant code example

@app.route('/resource', methods=['POST'])
def update_text():
    key = request.args.get('key')  # Noncompliant
    data = request.get_data()
    # Process using key from query parameter
    return 'Updated'

Compliant solution

@app.route('/users/<user_id>', methods=['POST'])
def update_user(user_id):
    data = request.get_json()  # Get data from request body
    # Process user_id from path parameter
    return 'Updated'

Resources

Documentation