seltzer 0.4.0

  • Installing
  • Versions
  • 0

Seltzer #

pub package Build Status

An elegant and rich cross-platform HTTP library for Dart.

Getting Started #

You can use Seltzer as an object-oriented HTTP service or simply use top-level convenience methods like get and post directly.

Using HTTP the service #

If you are using Seltzer with dependency injection:

import 'dart:async';

import 'package:seltzer/seltzer.dart';
import 'package:seltzer/platform/vm.dart';

void main() {
  new MyTwitterService(const VmSeltzerHttp()).tweet('Hello World!');

class MyTwitterService {
  final SeltzerHttp _http;
  // Uses the SeltzerHttp service to send a tweet.
  // This means if we are in the browser or the VM we can expect
  // our http service to work about the same.
  Future<Null> tweet(String message) => ...

Using top-level methods #

For simpler applications or scripts, Seltzer also provides a series of top-level convenience methods that automatically use a singleton instance of SeltzerHttp.

In your main() function, you just need to configure what platform you are expecting once:

import 'package:seltzer/seltzer.dart' as seltzer;
import 'package:seltzer/platform/browser.dart';

main() async {
  final response = await seltzer.get('some/url.json').send().first;
  print('Retrieved: ${await response.readAsString()}');

Using the WebSocket service #

import 'dart:async';

import 'package:seltzer/seltzer.dart';
import 'package:seltzer/platform/vm.dart';

void main() {
  var service = new MyMessageService(connect('ws://'));
  service.sendMessage('Hello World!');

class MyMessageService {
  final SeltzerWebSocket _webSocket;
  // Uses a SeltzerWebSocket to send a string message to a peer.
  // This means if we are in the browser or the server we can expect
  // our WebSocket to work about the same.
  Future<Null> sendMessage(String message) => _webSocket.sendString(message);

Changelog #

0.4.0 #

  • BREAKING readAs<Bytes|String> to return a Stream and Future instead
    • This is due to the potentially streaming nature of network and file i/o
    • For example, HTTP servers commonly send chunked responses
  • Added readAsBytesAll to auto-concatenate buffers together
  • Fix various strong-mode warnings

0.3.0 #

  • Use WebSocketChannel as the backing implementation for sockets
  • Replace sendX and close methods to return void instead of Future

0.2.4-alpha #

  • Added ReplaySeltzerHttp and SeltzerHttpRecorder for testing

0.2.3-alpha #

  • Added SeltzerSocketClosedEvent with information why close occurred
  • Rename the Server implementations to Vm since they work on Flutter
  • Simplified how to extend/transform HTTP clients
  • Removed CannedSeltzerHttp; to be re-added/re-worked by 0.3

0.2.2-alpha #

  • Consolidated interfaces of SeltzerMessage and SeltzerHttpResponse
    • Both support synchronous readAsString and readAsBytes
  • Fixed various strong mode warnings related to type inference
  • Moved "echo" servers from bin/ to tool/ (implementation detail)

0.2.0-alpha #

  • Added CannedHttpResponse and the platform/testing.dart library
  • Added response headers to SeltzerHttpResponse

Use this package as a library

1. Depend on it

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

  seltzer: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:seltzer/seltzer.dart';
Version Uploaded Documentation Archive
0.4.0 Dec 31, 2016 Go to the documentation of seltzer 0.4.0 Download seltzer 0.4.0 archive
0.3.0 Dec 23, 2016 Go to the documentation of seltzer 0.3.0 Download seltzer 0.3.0 archive
0.0.1 Sep 26, 2016 Go to the documentation of seltzer 0.0.1 Download seltzer 0.0.1 archive
0.2.3-alpha Nov 14, 2016 Go to the documentation of seltzer 0.2.3-alpha Download seltzer 0.2.3-alpha archive
0.2.1-alpha Oct 27, 2016 Go to the documentation of seltzer 0.2.1-alpha Download seltzer 0.2.1-alpha archive
0.1.0-alpha Oct 21, 2016 Go to the documentation of seltzer 0.1.0-alpha Download seltzer 0.1.0-alpha archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0