seltzer 0.4.0

  • Installing
  • Versions
  • 35


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);



  • 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


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


  • Added ReplaySeltzerHttp and SeltzerHttpRecorder for testing


  • 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


  • 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)


  • 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


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
90 / 100
Reflects how tidy and up-to-date the package is. [more]
42 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: unsure


  • Fix platform conflicts.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 errors 6 hints.

    Make sure that the imported libraries are not in conflict. Detected components: html, isolate. null

    Strong-mode analysis of lib/src/context.dart failed with the following error:

    line: 25 col: 10
    The expression in an assert must be of type 'bool'.

    Similar analysis of the following files failed:

    • lib/src/interface/http_request.dart (hint)
    • lib/src/interface/http_response.dart (hint)
    • lib/src/interface/socket_message.dart (hint)
    • lib/src/internal/echo.dart (hint)
  • Package is getting outdated.

    The package was released 76 weeks ago.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use seltzer.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
meta ^1.0.4 1.1.5
quiver ^0.23.0 0.23.0 0.29.0+1
reply 0.1.2-dev 0.1.2-dev
web_socket_channel ^1.0.4 1.0.8
Transitive dependencies
async 2.0.7
charcode 1.1.1
collection 1.14.10
convert 2.0.1
crypto 2.0.5
matcher 0.12.3
path 1.6.1
stack_trace 1.9.2
stream_channel 1.6.7+1
typed_data 1.1.5
Dev dependencies
dart_style >=0.2.10
test >=0.12.15