Request
類別¶
您可以在*路徑操作函式*或依賴項中宣告一個類型為 Request
的參數,然後您可以直接存取原始請求物件,無需任何驗證等等。
您可以直接從 fastapi
導入它
from fastapi import Request
提示
當您想要定義與 HTTP 和 WebSocket 相容的依賴項時,您可以定義一個接受 HTTPConnection
而不是 Request
或 WebSocket
的參數。
fastapi.Request ¶
Request(scope, receive=empty_receive, send=empty_send)
基底: HTTPConnection
參數 | 說明 |
---|---|
scope
|
類型: |
receive
|
類型: |
send
|
類型: |
原始碼位於 starlette/requests.py
194 195 196 197 198 199 200 201 |
|
url_for ¶
url_for(name, /, **path_params)
參數 | 說明 |
---|---|
名稱
|
類型: |
**path_params
|
類型: |
原始碼位於 starlette/requests.py
177 178 179 180 |
|
stream async
¶
stream()
原始碼位於 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()
原始碼位於 starlette/requests.py
231 232 233 234 235 236 237 |
|
json async
¶
json()
原始碼位於 starlette/requests.py
239 240 241 242 243 |
|
form ¶
form(*, max_files=1000, max_fields=1000)
參數 | 說明 |
---|---|
max_files(最大檔案數)
|
類型: |
max_fields(最大欄位數)
|
類型: |
原始碼位於 starlette/requests.py
273 274 275 276 |
|
關閉 async
¶
close()
原始碼位於 starlette/requests.py
278 279 280 |
|
已斷線 async
¶
is_disconnected()
原始碼位於 starlette/requests.py
282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
發送推播承諾 async
¶
send_push_promise(path)
參數 | 說明 |
---|---|
路徑
|
類型: |
原始碼位於 starlette/requests.py
296 297 298 299 300 301 302 |
|