0
0
Flaskframework~10 mins

Request object properties in Flask - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Request object properties
Client sends HTTP request
Flask receives request
Request object created
Access properties: method, url, headers, args, form, json
Use properties in route function
Send response back to client
When Flask gets a request, it creates a Request object. You can then read its properties like method, URL, headers, and data to handle the request.
Execution Sample
Flask
from flask import Flask, request
app = Flask(__name__)

@app.route('/submit', methods=['GET', 'POST'])
def submit():
    return f"Method: {request.method}, URL: {request.url}"
This code shows how to read the HTTP method and URL from the Flask request object inside a route.
Execution Table
StepActionRequest.methodRequest.urlOutput
1Client sends GET request to /submitGEThttp://localhost/submitNone yet
2Flask creates Request objectGEThttp://localhost/submitNone yet
3Route function runs, reads request.method and request.urlGEThttp://localhost/submitMethod: GET, URL: http://localhost/submit
4Response sent back with output stringGEThttp://localhost/submitMethod: GET, URL: http://localhost/submit
5Client receives responseGEThttp://localhost/submitMethod: GET, URL: http://localhost/submit
6Client sends POST request to /submitPOSThttp://localhost/submitNone yet
7Flask creates Request objectPOSThttp://localhost/submitNone yet
8Route function runs, reads request.method and request.urlPOSThttp://localhost/submitMethod: POST, URL: http://localhost/submit
9Response sent back with output stringPOSThttp://localhost/submitMethod: POST, URL: http://localhost/submit
10Client receives responsePOSThttp://localhost/submitMethod: POST, URL: http://localhost/submit
💡 Execution stops after response is sent back to client.
Variable Tracker
VariableStartAfter Step 2After Step 7Final
request.methodNoneGETPOSTPOST
request.urlNonehttp://localhost/submithttp://localhost/submithttp://localhost/submit
Key Moments - 2 Insights
Why does request.method change between steps 2 and 7?
Because each HTTP request creates a new Request object with its own method property. Step 2 is for the GET request, step 7 is for the POST request.
Can request.url be different for the same route?
Yes, request.url includes the full URL including query parameters, so it can vary even if the route path is the same.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the request.method at step 8?
AGET
BPOST
CPUT
DDELETE
💡 Hint
Check the 'Request.method' column at step 8 in the execution_table.
At which step does Flask create the Request object for the POST request?
AStep 2
BStep 6
CStep 7
DStep 8
💡 Hint
Look for the step where 'Flask creates Request object' with method POST.
If the client sends a GET request with query parameters, which Request property holds them?
Arequest.args
Brequest.form
Crequest.json
Drequest.headers
💡 Hint
Query parameters are accessed via request.args in Flask.
Concept Snapshot
Flask creates a Request object for each HTTP request.
Use request.method to get HTTP method (GET, POST, etc).
Use request.url for full URL.
Use request.args for query parameters.
Use request.form for form data.
Use request.json for JSON body data.
Full Transcript
When a client sends an HTTP request to a Flask app, Flask creates a Request object representing that request. This object has properties like method, url, args, form, and json. The method tells you if the request is GET or POST. The url shows the full address requested. Query parameters are in args, form data in form, and JSON data in json. The route function can read these properties to decide how to respond. Each new request creates a new Request object with its own properties. This trace showed GET and POST requests to the same route, how Flask creates the Request object, and how the route reads method and url to build a response.