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',
},
);