shelf_body_parser 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 70

A Middleware for Shelf.

Created from templates made available by Lijian under a BSD-style license.

Usage #

A simple usage example:

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_body_parser/shelf_body_parser.dart';

// Run shelf server and host a [Service] instance on port 8080.
void main() async {
  var handler = const Pipeline()
      .addMiddleware(logRequests())
      .addMiddleware(bodyParser(storeOriginalBuffer: false))
      .addHandler(_messages);
  final server = await shelf_io.serve(handler, 'localhost', 8080);
  print('Server running on localhost:${server.port}');
}

Future<Response> _messages(Request request) async {
  // 查看 body 数据(需打开 storeOriginalBuffer)
  print((request.context['originalBuffer'] as Buffer).store);
  // 获取 get 参数
  print((request.context['query'] as Map<String, String>)['aaa']);
  // 获取 post 文本参数(application/x-www-form-urlencoded)
  print((request.context['postParams'] as Map<String, dynamic>)['xx']);
  // 获取 post 二进制流(form-data)
  final file = new File('./ccc.png');
  IOSink fileSink = file.openWrite();
  await (request.context['postFileParams'] as Map<String, List<FileParams>>)['zzz1'][0].part.pipe(fileSink);
  fileSink.close();
  print(((request.context['postFileParams'] as Map<String, dynamic>)['yyy'] as List<String>)[0]);

  print(request.context);
  return Response.ok('[]');
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.6 #

  • 调整 二进制流上传 参数

1.0.5 #

  • 调整 import关系

1.0.4 #

  • 调整 pubspec

1.0.3 #

  • 清理analysis

1.0.2 #

  • File 类改名为 FileParams 存储MimeMultipart 方便文件输出
  • 清理无用导出文件

1.0.1 #

  • Initial version, created by lijian

1.0.0 #

  • Initial version, created by lijian

example/shelf_body_parser_example.dart

import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_body_parser/shelf_body_parser.dart';

// Run shelf server and host a [Service] instance on port 8080.
void main() async {
  var handler = const Pipeline()
      .addMiddleware(logRequests())
      .addMiddleware(bodyParser(storeOriginalBuffer: false))
      .addHandler(_messages);
  final server = await shelf_io.serve(handler, 'localhost', 9090);
  print('Server running on localhost:${server.port}');
}

Future<Response> _messages(Request request) async {
  // 查看 body 数据(需 storeOriginalBuffer:true)
  print((request.context['originalBuffer'] as Buffer).store);
  // 获取 get 参数
  print((request.context['query'] as Map<String, String>)['aaa']);
  // 获取 post 文本参数(application/x-www-form-urlencoded)
  print((request.context['postParams'] as Map<String, dynamic>)['xx']);
  // 获取 post 二进制流(form-data)
  final file = File('./ccc.png');
  IOSink fileSink = file.openWrite();
  await (request.context['postFileParams'] as Map<String, List<dynamic>>)['zzz1'][0].part.pipe(fileSink);
  await fileSink.close();
  print(((request.context['postFileParams'] as Map<String, dynamic>)['yyy'] as List<String>)[0]);

  print(request.context);
  return Response.ok('[]');
}

Use this package as a library

1. Depend on it

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


dependencies:
  shelf_body_parser: ^1.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:shelf_body_parser/shelf_body_parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:shelf_body_parser/shelf_body_parser.dart with components: io.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
http_parser ^3.1.3 3.1.3
mime ^0.9.6+3 0.9.6+3
shelf ^0.7.5 0.7.5
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
meta 1.1.7
path 1.6.4
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.7.0
test ^1.6.0