ai_http 0.1.0 ai_http: ^0.1.0 copied to clipboard
ai_http is the dart package of http. ai_http that makes you fall in love with http management
ai_http #
English Document | 中文文档 |
---|
我们的宗旨是:帮助开发者更加便利开发、切身体会编程之美! #
ai_http: #
*1、支持:RESTful
*2、支持:拦截器
*3、....
ai_http 在项目中的实战应用flutter sample
1.安装 #
使用当前包作为依赖库
1. 依赖此库 #
在文件 'pubspec.yaml' 中添加
dependencies:
ai_http: ^version
或以这种方式添加
# Http package.
ai_http:
git:
url: https://github.com/pdliuw/ai_http.git
2. 安装此库 #
你可以通过下面的命令行来安装此库
$ flutter pub get
你也可以通过项目开发工具通过可视化操作来执行上述步骤
3. 导入此库 #
现在,在你的Dart编辑代码中,你可以使用:
import 'package:ai_http/ai_http.dart';
2.使用 #
1.在你的项目入口'main.dart'中配置: #
ai_http 全局配置
void main() {
///
/// 配置Http
AiHttp.globalConfig(
baseUrl: "https://www.baidu.com/",
requestInterceptor: RequestInterceptorWell(),
responseInterceptor: ResponseInterceptorWell(),
);
runApp(
......
);
}
///
/// RequestInterceptorWell
class RequestInterceptorWell extends RequestInterceptor {
@override
Future<RequestRule> interceptor(RequestRule requestRule) async {
//do something
return requestRule;
}
}
///
/// ResponseInterceptorWell
class ResponseInterceptorWell extends ResponseInterceptor {
@override
interceptor(ResponseInterceptorModel responseInterceptorModel) {
Response response = responseInterceptorModel.response;
ResponseCallback responseCallback =
responseInterceptorModel.responseCallback;
OSError osError = responseInterceptorModel.osError;
//do something
return false;
}
}
待办 #
证书 #
BSD 3-Clause License
Copyright (c) 2020, pdliuw
All rights reserved.