http_mock 1.0.0

  • README.md
  • Installing
  • Versions
  • 1

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

client.router
  ..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:


dependencies:
  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';
  
Version Uploaded Documentation Archive
1.0.0 Jul 20, 2017 Go to the documentation of http_mock 1.0.0 Download http_mock 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
2
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
1
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

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.0.0.
 
 Because http_mock depends on angel_route >=1.0.0-dev+1 <2.0.6 which requires SDK version <2.0.0, version solving failed.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

Package is getting outdated. (-25.21 points)

The package was released 65 weeks ago.

The description is too short. (-20 points)

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

Maintain an example. (-10 points)

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 http_mock.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0