[REST API] Query string vs Route parameter

 Query string vs Route parameter

How did I encounter this?

While practicing on Flask, I saw the following cases:

@app.route('/login')
def login():
    password = request.args.get('password')
    email = request.args.get('email')
    print(password, email)

values from the URL are retrieved using flask.request.args.get(<parameter_name>).

@app.route('/hello/<user>')
def hello_name(user):
    return render_template('variable.html', name=user)

the value of the specified parameter is automatically retrieved and passed into the function

I got to wonder the difference between them.

Explanation

  • Query String
    Query strings (like ?username=hyobin) are appended to the URL after `?` to provide parameters in key-value. These are optional or flexible: the key-value pairs can be added, removed, or changed without modifying the routes themselves
  • Route Parameter
    Route parameters are embedded in the path itself. It is literally part of the path. This leads to different and actual paths.

Comments