json2http 1.1.1
json2http: ^1.1.1 copied to clipboard
json2http is a command-line tool that relies on json2class to convert specified JSON(5) files into HTTP request code.
example/main.dart
import 'json2http.dart';
main() async {
// 全局配置
Json2http.setPlan = (p) {
p.baseURL = 'https://qqlykm.cn';
p.process = (reply) {
final data = reply.data;
if (data is Map) {
if (data['code'] != 200) {
// 设置 error 决定是否抛出异常
// 避免每个接口都取判断状态码
reply.error = data['msg'];
}
}
};
};
// 发起请求
final plan = await Json2http.single.apibloodindex((p) {
// 单次请求的参数配置
p.params.father = 'A';
p.params.mother = 'O';
});
// 返回值
print(plan.res.toJson());
print(plan.res.msg);
print(plan.res.data.possible.elementAtOrNull(0));
print(plan.res.data.impossible.elementAtOrNull(0));
}