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>The main difference is that the URL triggering your function will be different. </p>

<p>If you use the flask function <a href="http://flask.pocoo.org/docs/0.11/api/#flask.url_for" rel="nofollow">url_for</a>(that i REALLY recommend), the URL structure returned by the function will be different because all the variables that you use and are not part of the endpoint will be treated like query parameters. </p>

<p>So in this case you can change your route without impacting your existing codebase. </p>

<p>In other words in your case you would have: </p>

<p>Using method variables: </p>

<pre><code>url_for('get_user', id=1) =&gt; '/api/users/1'
</code></pre>

<p>Without method variables:</p>

<pre><code>url_for('get_user', id=1) =&gt; '/api/users?id=1'
</code></pre>

<p>Which approach is better depends from the context you are working on. 
If you want to realize a REST based API you should define the identifiers argument as path arguments and the metadata as query arguments(you can read more about that <a href="https://tools.ietf.org/html/rfc3986" rel="nofollow">here</a>). </p>

python python-3.x flask flask-restful