httpclient_api 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

httpclient_api #

【一】 HttpClientAPI 是基于 Dart 的原生 HttpClient 库封装的一套高性能网络框架 API。 HttpClientAPI 网络框架是致敬iOS和Android的网络封装实现的一套方案,其中主要对请求中的: (1)全局URL设置 (2)请求超时时间设置 (3)请求体参数设置 (4)请求头参数设置 (5)响应处理数据设置
------------------进行了封装和容错处理,使得项目网络开发安全,简介方便,高效。

【二】 HttpClientAPI 框架通过将要发起请求前的 APIWillRequestHandler 回调数据,可以方便开发者对请求数据进行检查。 HttpClientAPI 框架通过响应结果的 APISuccessResponseHandler 回调数据,返回给开发者成功的网络响应数据。 HttpClientAPI 框架通过响应结果的 APIFailureResponseHandler 回调数据,返回给开发者失败的网络响应数据。

【三】 HttpClientAPI 支持本地 File 文件对象(包括同时多个File对象)上传服务器功能; HttpClientAPI 还支持 ImageProvider 对象(包括同时多个ImageProvider对象)上传服务器功能; HttpClientAPI Welcome to use.

欢迎大家使用 HttpClientAPI。 HttpClientAPI 是一位中国开发者编写的开源SDK,请支持。

【The synopsis of function】 【一】 The HttpClientAPI is a set of high-performance network framework apis encapsulated in the Dart native HttpClient library. The HttpClientAPI network framework is a set of solutions that pay tribute to the network encapsulation implementation of iOS and Android, mainly for requests: (1) global URL setting (2) request timeout setting (3) request body parameter setting (4) request header parameter setting (5) the response processing data Settings are encapsulated and fault-tolerant -------------------making the project network development safe, simple, convenient and efficient.

【二】 The HttpClientAPI framework makes it easy for developers to examine the request data by calling back the APIWillRequestHandler before the request is to be made. HttpClientAPI APISuccessResponseHandler callback data frame by response results, returned to the developer network response data of success. HttpClientAPI APIFailureResponseHandler callback data frame by response results, returned to the developer failed network response data.

【三】 The HttpClientAPI supports uploading of local File objects (including multiple File objects at the same time) to the server. The HttpClientAPI also supports uploading of ImageProvider objects (including multiple ImageProvider objects at the same time) to the server.

You are welcome to use the HttpClientAPI. HttpClientAPI is an open source SDK written by a Chinese developer, please support.

Post and Get #

/// 全局 BaseUrl设置
HttpClientAPI.setAPIRequestBaseUrl('https://api-test.saicmobility.com');

/// 全局 请求超时设置
HttpClientAPI.setAPIRequestTimeout(10);

//// POST 请求,
<!-- urlMethod: 请求方式枚举,urlPath:URL路径 -->
<!-- urlPath:URL路径(BaseUrl不传默认使用全局配置的URL) -->
HttpClientAPI.request(
      urlMethod: URLMethod.POST,
        urlPath: '/auth/v2/emergencycontact/passenger/checkhavecontact',
        success: (Map<String,dynamic> response) {
          <!-- 成功回调数据 -->
      },failure: (int code, String msg, String rawResponseString){
          <!-- 失败回调数据 -->
  },willRequest: (HttpClientRequest request){
          <!-- 将要发起请求,回调请求数据检查 -->
 });

http post File or List

File f = File('/Users/a/Downloads/IMG_E3DD8D0B3C82-1.jpeg');

/// 单个文件上传服务器
<!-- urlPath:URL路径(BaseUrl不传默认使用全局配置的URL) -->
HttpClientAPI.upLoadFile(baseUrl: 'http://fs.cshuljanyu.com',
                         urlPath: '/upload/logo?access_token=a
                            file: f,
                         success: (Map<String,dynamic> response) {
       <!-- 成功回调数据 -->
    },failure: (int code, String msg, String rawResponseString){
       <!-- 失败回调数据 -->
    },willFile: (HttpClientFileInfo fileInfo){
       <!-- 将要上传文件,回调上传文件信息检查 -->
 });


File ftwo = File('/Users/a/Downloads/IMG_9E9EFA94A471-1.jpeg');

/// 多个文件上传服务器
<!-- urlPath:URL路径(BaseUrl不传默认使用全局配置的URL) -->
HttpClientAPI.upLoadFile(baseUrl: 'http://fs.cshuanyu.com',
                         urlPath: '/upload/logo?access_token=a
                        fileList: [f,ftwo],
                         success: (Map<String,dynamic> response) {
       <!-- 成功回调数据 -->
 },failure: (int code, String msg, String rawResponseString){
       <!-- 失败回调数据 -->
 },willFile: (HttpClientFileInfo fileInfo){
       <!-- 将要上传文件,回调上传文件信息检查 -->
 });

http post ImageProvider or List

Image icon = Image.asset('images/1.0X/232017s8826z6h822p76jm.jpg');

/// Image UI 单张图片上传
<!-- urlPath:URL路径(BaseUrl不传默认使用全局配置的URL) -->
HttpClientAPI.upLoadImage(baseUrl: 'http://fs.cshusssu.com',
                          urlPath: '/upload/logo?access_to',
                    imageProvider: icon.image,
                          success: (Map<String,dynamic> response) {
       <!-- 成功回调数据 -->
},failure: (int code, String msg, String rawResponseString){
       <!-- 失败回调数据 -->
});
Image iconTwo = Image.asset('images/1.0X/timg.jpeg');
/// Image UI 图片数组上传
<!-- urlPath:URL路径(BaseUrl不传默认使用全局配置的URL) -->
HttpClientAPI.upLoadImageList(baseUrl: 'http://fs.shhshs.com',
                              urlPath: '/upload/logo?access_to',
                    imageProviderList: [icon.image,iconTwo.image],
                              success: (Map<String,dynamic> response) {
        <!-- 成功回调数据 -->
},failure: (int code, String msg, String rawResponseString){
        <!-- 失败回调数据 -->
});
Getting Started
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.

For help getting started with Flutter, view our 
[online documentation](https://flutter.dev/docs), which offers tutorials, 
samples, guidance on mobile development, and a full API reference.

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

[0.0.4] - TODO:httpclient_api: #

基于 HttpClient 封装的网络数据流框架,完成基本封装.

[0.0.6] - TODO:httpclient_api: #

基于 HttpClient 封装的网络数据流框架,支持设置请求连接超时时间功能.

[0.0.7] - TODO:httpclient_api: #

基于 HttpClient 新增本地文件File对象(支持同时多个File对象)上传服务器功能.

[0.0.9] - TODO:httpclient_api: #

基于 HttpClient 新增 ImageProvider(支持同时多个ImageProvider)上传服务器功能.

[0.1.2] - TODO:httpclient_api: #

基于 HttpClient 封装的网络数据流框架,添加使用案例演示,完善使用文档,完善SDK,完成release基础版.

example/lib/main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  httpclient_api: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:httpclient_api/httpclient_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
11
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/client/client_api.dart.

Run flutter format to format lib/client/client_api.dart.

Format lib/client/client_config.dart.

Run flutter format to format lib/client/client_config.dart.

Format lib/client/client_error.dart.

Run flutter format to format lib/client/client_error.dart.

Format lib/client/client_manager.dart.

Run flutter format to format lib/client/client_manager.dart.

Format lib/client/client_uploader.dart.

Run flutter format to format lib/client/client_uploader.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test