Fresh Http 是一個基於 `http` 套件建構的 Flutter/Dart 套件,提供自動重新整理的 HTTP 客戶端。它會自動處理驗證金鑰的重新整理,確保在無需手動管理金鑰的情況下實現無縫 API 呼叫。對於需要安全且持續存取已驗證 API 的應用程式而言,該客戶端透過透明地重新整理過期金鑰來減少重複程式碼並提升可靠性。該客戶端可與現有的 HTTP 工作流程順暢整合,並支援所有主要平台,包括網頁、行動裝置和桌面。
適用情境
需要刷新令牌的 API
安全的移動和Web應用程式
減少驗證樣板程式碼
自動令牌管理
有狀態的 API 客戶端
主要特色
自動令牌刷新
基於 `package:http`
透明的身分驗證處理
跨平台支援
所需的設定最少
適合對象
使用 JWT 或 OAuth2 的應用
尋求降低認證複雜性的開發者
需要可靠 API 連接的專案
重視開發者體驗的團隊
頻繁進行 API 互動的應用程式
使用建議
需要自定義令牌刷新邏輯
依賴外部驗證狀態管理
僅限基於 HTTP 的 API
不適用於一次性請求
令牌刷新流程中需要適當的錯誤處理
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Fresh 🍋
A collection of packages for automatic token refresh in Dart and Flutter. Fresh handles refreshing, caching, and attaching authentication tokens transparently so your API calls just work.
Why Fresh?
Token-based authentication seems simple until you handle the edge cases: tokens expire mid-session, multiple requests fail at the same time triggering duplicate refreshes, refresh tokens get revoked, and you need to route users to login when auth is lost. Fresh handles all of this so you don't have to.
No more manual 401 handling scattered across your codebase
No more race conditions when concurrent requests trigger simultaneous refreshes
No more stale tokens causing request failures - expired tokens are refreshed proactively before the request is even sent