http_api_handler 是一個專為簡化 HTTP API 互動而設計的 Flutter 套件,提供簡潔的方法來發起請求、處理檔案上傳和下載,適用於多個平台。它提供一個清晰直覺的介面,減少樣板程式碼,同時支援常見的 HTTP 操作,如 GET、POST、PUT 和 DELETE。此套件以易用性為核心設計,可無縫整合至針對 Android、iOS、Web、macOS、Windows 和 Linux 的 Flutter 應用中。透過抽象複雜的網路邏輯,該套件提升開發者生產力。
適用情境
呼叫 REST API
上傳檔案到伺服器
從 API 下載檔案
處理 JSON 回應
簡化網路請求管理
跨平台 HTTP 通訊
主要特色
支援檔案上傳和下載
內建錯誤處理
跨平台相容性
簡單 API 語法
自動 JSON 解析
請求取消
適合對象
Flutter 開發人員建構 API 驅動的應用程式
需要檔案傳輸功能的專案
注重快速開發的團隊
針對多個平台的應用
尋求最小化樣板程式碼的開發者
使用建議
與原始的 http 包相比,自定義選項有限
依賴外部 http 庫
可能需要額外設定以進行進階驗證
不太適合高度複雜的請求工作流程
最適合標準 REST API
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
HTTP API Handler
A powerful and flexible Flutter package for handling HTTP API requests with built-in logging, error handling, and file operations. Designed to simplify API integration in Flutter applications.
Features 🚀
✨ Easy-to-use HTTP methods (GET, POST, PUT, DELETE)
📁 File upload support (single and multiple files)
⬇️ File download capability
📝 Built-in logging system
❌ Comprehensive error handling
🔐 Authentication token support
🔍 Query parameters support
🎯 Custom base URL support
🧪 Fully tested
Installation 💻
Add this to your package's pubspec.yaml file:
dependencies:http_api_handler:^1.0.0
Then run:
flutter pub get
Usage 📱
Initialize the API Handler
final api = ApiHandler(
baseURL: 'https://api.example.com', // Your API base URL
authToken: 'your_auth_token', // Optional: JWT or other auth token
enableLogs: true, // Enable/disable logging
additionalHeaders: { // Optional: Additional headers'Custom-Header': 'Value',
},
);