Request
类¶
您可以将路径操作函数或依赖关系中的参数声明为 Request
类型,这样就可以直接访问原始请求对象,而无需任何操作,例如验证。
你可以直接从 fastapi
导入:
from fastapi import Request
Tip
如果要定义同时与 HTTP 和 WebSockets 兼容的依赖关系,可以定义一个使用 "HTTPConnection "而不是 "Request "或 "WebSocket "的参数。
fastapi.Request
¶
Request(scope, receive=empty_receive, send=empty_send)
Bases: HTTPConnection
PARAMETER | DESCRIPTION |
---|---|
scope
|
TYPE:
|
receive
|
TYPE:
|
send
|
TYPE:
|
Source code in starlette/requests.py
202 203 204 205 206 207 208 209 210 211 |
|
url_for
¶
url_for(name, /, **path_params)
PARAMETER | DESCRIPTION |
---|---|
name
|
TYPE:
|
**path_params
|
TYPE:
|
Source code in starlette/requests.py
185 186 187 188 |
|
stream
async
¶
stream()
Source code in starlette/requests.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
body
async
¶
body()
Source code in starlette/requests.py
241 242 243 244 245 246 247 |
|
json
async
¶
json()
Source code in starlette/requests.py
249 250 251 252 253 |
|
form
¶
form(*, max_files=1000, max_fields=1000)
PARAMETER | DESCRIPTION |
---|---|
max_files
|
TYPE:
|
max_fields
|
TYPE:
|
Source code in starlette/requests.py
285 286 287 288 289 290 |
|
close
async
¶
close()
Source code in starlette/requests.py
292 293 294 |
|
is_disconnected
async
¶
is_disconnected()
Source code in starlette/requests.py
296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
send_push_promise
async
¶
send_push_promise(path)
PARAMETER | DESCRIPTION |
---|---|
path
|
TYPE:
|
Source code in starlette/requests.py
310 311 312 313 314 315 316 317 318 319 320 |
|