Difference between GET data as a function parameter and an item from requests.arg
<p>I would like to know if there is any difference between:</p>

<pre><code>@app.route('/api/users/&lt;int:id&gt;', methods=['GET'])
def get_user(id):
    pass  # handle user here with given id
</code></pre>

<p>and</p>

<pre><code>@app.route('/api/users')
def get_user():
    id = request.args.get('id')
    # handle user here with given id
</code></pre>

<p>Furthermore, is there a way to get multiple parameters in the former? Can they be optional parameters?</p>

<p>Yes, it is. </p>

<p>First method:</p>

<pre><code>@app.route('/api/users/&lt;int:id&gt;', methods=['GET']
def get_user(id):
    pass  # handle user here with given id
</code></pre>

<p>Defines a route and a method. This function is only triggered with this method over this path.</p>

<p>Second method:</p>

<pre><code>@app.route('/api/users')
def get_user():
    id = request.args.get('id')
    # handle user here with given id
</code></pre>

<p>It just defines a route. You can execute the function with all methods. </p>

<p>The route in the first method is: <code>webexample.com/api/users/1</code> for user 1</p>

<p>The route in the second one is: <code>webexample.com/api/users?id=1</code> for user 1</p>

python python-3.x flask flask-restful