http_mock 1.0.0

  • README.md
  • Installing
  • Versions
  • 58

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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

Analysis

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

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
25 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80 / 100
Overall score:
Weighted score of the above. [more]
58
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

Primary library: package:http_mock/http_mock.dart with components: io.

Suggestions

  • Maintain CHANGELOG.md.

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

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

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

    Strong-mode analysis of lib/http_mock.dart gave the following hint:

    line: 50 col: 19
    'JSON' is deprecated and shouldn't be used.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0
angel_route ^1.0.0 1.0.8 2.0.6
http ^0.11.3 0.11.3+16
Transitive dependencies
async 2.0.7
charcode 1.1.1
collection 1.14.10
http_parser 3.1.2
path 1.6.1
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
test ^0.12.0