Request
类¶
你可以在 路径操作函数 或依赖项中声明一个参数为 Request
类型,然后你可以直接访问原始请求对象,而无需任何验证等操作。
你可以直接从 fastapi
导入它:
from fastapi import Request
/// 提示
当你想要定义一个依赖项,使其同时兼容 HTTP 和 WebSocket 时,你可以定义一个参数,该参数接受 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
194 195 196 197 198 199 200 201 |
|
url_for
¶
url_for(name, /, **path_params)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
**path_params |
TYPE:
|
Source code in starlette/requests.py
177 178 179 180 |
|
stream
async
¶
stream()
Source code in starlette/requests.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
body
async
¶
body()
Source code in starlette/requests.py
231 232 233 234 235 236 237 |
|
json
async
¶
json()
Source code in starlette/requests.py
239 240 241 242 243 |
|
form
¶
form(*, max_files=1000, max_fields=1000)
PARAMETER | DESCRIPTION |
---|---|
max_files |
TYPE:
|
max_fields |
TYPE:
|
Source code in starlette/requests.py
273 274 275 276 |
|
close
async
¶
close()
Source code in starlette/requests.py
278 279 280 |
|
is_disconnected
async
¶
is_disconnected()
Source code in starlette/requests.py
282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
send_push_promise
async
¶
send_push_promise(path)
PARAMETER | DESCRIPTION |
---|---|
path |
TYPE:
|
Source code in starlette/requests.py
296 297 298 299 300 301 302 |
|