http_mock 1.0.0

http_mock #

Pub build status

A package:http client that can mock server responses.

Usage #

Instead of sending requests over a network, the MockClient class is also a server in itself. It uses the cross-platform angel_route library to provide you with a routing solution that supports path parameters and middleware out-of-the-box.

All your handlers just need to accept a MockHttpContext. If they return true, then other handlers will be allowed to run (effectively accomplishing a middleware concept). Otherwise, the return value will be processed.

You can return:

  • a Response or StreamedResponse
  • null or nothing - do not write anything else to the server
  • Anything else - will be serialized via JSON.encode
var client = new http.MockClient();

  ..get('/hello/:name', (http.MockHttpContext ctx) {
    // Return a plain response
    return new http.Response('Hello, ${ctx.request.params["name"]}!', 200);
  ..all('*', (http.MockHttpContext ctx) {
    return new http.Response('404 Not Found', 404);

// And then, in a test...
var response = await client.get('/hello/world');
expect(response.body, 'Hello, world!');

Use this package as a library

1. Depend on it

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

  http_mock: ^1.0.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:http_mock/http_mock.dart';
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.19.0