http_mock 1.0.0

  • README.md
  • Installing
  • Versions
  • 44

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]
5
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
59
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Aug 16, 2018, and provided a score, details, and suggestions below. Analysis was completed with status tool failures using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: unsure

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

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.

Fix platform conflicts.

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Maintain CHANGELOG.md.

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

Package is getting outdated.

The package was released 56 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.

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0