当前位置:网站首页>Flutter network and data storage framework construction-b1
Flutter network and data storage framework construction-b1
2022-07-03 18:57:00 【weixin_ thirty-eight million one hundred and seven thousand fou】
HitNet framework
Configuration based request encapsulation and hi_net Architecture building
enum HttpMethod{GET, POST, DELETE}
/// Basic request
abstract class BaseRequest{
var pathParams;
var useHttps = true;
String authority(){
return "api.devio.org";
}
HttpMethod httpMethod();
String path();
String url(){
Uri uri;
var pathStr = path();
// Splicing path Parameters
if(pathParams != null){
if(path().endsWith("/")){
pathStr = "${path()}$pathParams";
}else{
pathStr = "${path()}/$pathParams";
}
}
// htttp and https Switch
if(useHttps){
uri = Uri.https(authority(), pathStr,params);
}else{
uri = Uri.http(authority(), pathStr,params);
}
print("url:${uri.toString()}");
return uri.toString();
}
// Log in
bool needLogin();
Map<String,String>params = Map();
// Add parameter
BaseRequest add(String k,Object v){
params[k] = v.toString();
return this;
}
Map<String,dynamic> header = Map();
// add to header
BaseRequest addHeader(String k,Object v){
params[k] = v.toString();
return this;
}
}
import 'package:flutter_bilibli_app/http/request/base_request.dart';
class TestRequest extends BaseRequest{
@override
HttpMethod httpMethod() {
return HttpMethod.GET;
}
@override
bool needLogin() {
return false;
}
@override
String path() {
return 'uapi/test/test';
}
}
import 'package:flutter_bilibli_app/http/request/base_request.dart';
class HiNet{
HiNet._();
static HiNet? _instance;
static HiNet? getInstance(){
if(_instance == null){
_instance = HiNet._();
}
return _instance;
}
Future fire(BaseRequest request) async{
var response = await send(request);
var result = response['data'];
print(result);
return result;
}
Future<dynamic>send<T>(BaseRequest request) async{
print('url:${request.url()}');
print('method:${request.httpMethod()}');
request.addHeader("token", "123");
print('header:${request.header}');
return Future.value({
"statusCode":200,
"data":{"code":0,"message":'success'}
});
}
void printLog(log){
print('hi_net:${log.toString()}');
}
}
hi_net Unified exception and return handling and Adapter Pattern design
边栏推荐
- Scrape crawler framework
- 【光学】基于matlab介电常数计算【含Matlab源码 1926期】
- Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
- Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
- Introduction to SSH Remote execution command
- [combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
- Find the median of two positive arrays
- MySQL duplicate check
- Zero length array
- There are several levels of personal income tax
猜你喜欢
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
How many convolution methods does deep learning have? (including drawings)
How to read the source code [debug and observe the source code]
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Implementation of cqrs architecture mode under Kratos microservice framework
Kratos微服务框架下实现CQRS架构模式
SQL: special update operation
Simulation scheduling problem of SystemVerilog (1)
Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
随机推荐
Database creation, addition, deletion, modification and query
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
變化是永恒的主題
After nohup NPM start &, close the shell window directly, and the process closes accordingly
[leetcode weekly race] game 300 - 6110 Number of incremental paths in the grid graph - difficult
[combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)
Opencv learning notes (continuously updated)
High concurrency Architecture - read write separation
What does a really excellent CTO look like in my eyes
Reappearance of ASPP (atlas spatial pyramid pooling) code
flask 生成swagger文档
Simple solution of physical backup and restore of Damon database
Differential constrained SPFA
Change is the eternal theme
SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)
my. INI file not found
Typescript configuration
DriveSeg:动态驾驶场景分割数据集
leetcode:556. Next larger element III [simulation + change as little as possible]
Le changement est un thème éternel