Flask Request Api
π
2026-06-24 | π Flask
The Request class encapsulates all information sent by the HTTP request from the client.
Import the proxy object via from flask import request, and use it directly in view functions.
* * *
## Common Attributes Quick Reference
| Attribute | Type | Description | Example Value |
| --- | --- | --- | --- |
| method | str | HTTP request method | "GET", "POST" |
| path | str | URL path part (excluding domain and query string) | "/search" |
| full_path | str | Path + query string | "/search?q=tutorial" |
| url | str | Complete request URL (excluding query string) | "http://localhost:5000/search" |
| base_url | str | Same as url, removing the final query string | "http://localhost:5000/search" |
| url_root | str | Domain + application root path | "http://localhost:5000/" |
| host | str | Host header, including port | "localhost:5000" |
| host_url | str | scheme + host + application root | "http://localhost:5000/" |
| scheme | str | Protocol | "http", "https" |
| remote_addr | str | Client IP address | "127.0.0.1" |
| endpoint | str | Matched route endpoint | "index", "blog.show" |
| url_rule | Rule | Matched route rule object | Werkzeug Rule instance |
| view_args | dict | Dynamic variables in URL | {"post_id": 42} |
| blueprint | str | Current blueprint name | "auth", "blog" |
| blueprints | list | Current matched blueprint hierarchy list | |
| is_json | bool | Whether request Content-Type is JSON | True / False |
* * *
## Getting Request Data
| Attribute/Method | Type | Description |
| --- | --- | --- |
| args | MultiDict | URL query parameters. Access /search?q=flask β request.args.get("q") |
| form | MultiDict | POST form data (application/x-www-form-urlencoded or multipart/form-data) |
| json | dict / None | JSON request body (parsed as Python object). Returns None when not a JSON request |
| data | bytes | Raw request body data |
| files | FileMultiDict | Uploaded files. request.files returns FileStorage object |
| cookies | dict | Cookies sent by the client |
| headers | Headers | Request headers. Supports multiple access methods |
| get_json(force=False, silent=False, cache=True) | β | Parse JSON request body. force forces parsing non-JSON types, silent returns None on error |
> For MultiDict types like args and form, always use .get(key, default) method to get values. Directly accessing request.args for non-existent keys will raise KeyError (returning 400 error).
* * *
## Content Negotiation Attributes
| Attribute/Method | Description |
| --- | --- |
| accept_mimetypes | List of MIME types accepted by the client (MIMEAccept object) |
| accept_charsets | Character sets accepted by the client |
| accept_encodings | Encodings accepted by the client |
| accept_languages | Languages accepted by the client |
| content_type | Request Content-Type |
| content_length | Request body length (bytes) |
| content_md5 | MD5 checksum of request body |
* * *
## Code Examples
## Example
from flask import Flask, request
app = Flask( __name__ )
@app.route("/demo", methods=["GET","POST"])
def demo():
# Get query parameters
keyword= request.args.get("q","")
# Get form data
username = request.form.get("username","")
# Get JSON data
if request.is_json:
data = request.json
name = data.get("name","unknown")
# Get request headers
user_agent = request.headers.get("User-Agent","")
accept_lang = request.accept_languages.best
# Get URL information
url_info ={
"method": request.method,# "GET" or "POST"
"path": request.path,# "/demo"
"url": request.url,# complete URL
"remote_addr": request.remote_addr,# client IP
}
return url_info