expected_response 1.0.0+1

  • Readme
  • Changelog
  • Installing
  • 67

Expected Response Generator #

Create classes and generate code to make it easier to deal with http responses, make the behaviour of the response more verbose, generic, and dry.

Getting Started #

Installing #

Add the following to your pubspec

dependencies:
    expected_response: ^1.0.0

dev_dependencies:
    build_runner: ^1.0.0
    expected_response_generator: ^1.0.0

run pub get

Using #

See our example to see more.

@ExpectedResponse(allowedCodes: [200, 401, 403, 500])
class Mocked extends HttpBase<bool> {

  @EntryFunction()
  bool base(bool base) {
    _buildResponse(this, base);
    return true;
  }

  @Request()
  Future<ServerResponse> requestFunction(bool base) async => await request(this, base);

  @Response(200)
  void successResponse(ServerResponse response, bool base) {

  }

  Future<ServerResponse> request(Mocked me, bool base) async {
    return ServerResponse(200, '');
  }
}

When the function _buildResponse, the function that was generated, be evoke, it will request the server through the requestFunction, and behave for each response code allowed, and if is 200, will use the successResponse;

1.0.0 #

  • Create package
  • Create the annotations
    • ExpectedResponse
      • Responsable for indicate the class where the ecossystem will run, is the entry point of everything;
    • Response
      • Identify the behaviour expected for each response code returned from the http response
    • Request
      • Identify the function that must make the request
    • EntryFunction
      • Is the function that will evoke the generated function
  • Create ServerResponse, the abstract class that receives the http response
  • Created the UnrecognizedHttpResponse, the default behaviour for unknown responses
  • Created the HttpBase, the super class for every class annotated with @ExpectedResponse
  • Documented the annotations
  • Documented the helper classes
  • Create README
  • Add LICENSE

+1 #

  • Change the description

Use this package as a library

1. Depend on it

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


dependencies:
  expected_response: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:expected_response/expected_response.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:expected_response/expected_response.dart.

Health suggestions

Format lib/expected_response.dart.

Run dartfmt to format lib/expected_response.dart.

Format lib/src/annotations/entry_function.dart.

Run dartfmt to format lib/src/annotations/entry_function.dart.

Format lib/src/annotations/expected_response.dart.

Run dartfmt to format lib/src/annotations/expected_response.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/annotations/request.dart (Run dartfmt to format lib/src/annotations/request.dart.)
  • lib/src/annotations/response.dart (Run dartfmt to format lib/src/annotations/response.dart.)
  • lib/src/exceptions/unrecognized_http_exception.dart (Run dartfmt to format lib/src/exceptions/unrecognized_http_exception.dart.)
  • lib/src/http_base.dart (Run dartfmt to format lib/src/http_base.dart.)
  • lib/src/server_response.dart (Run dartfmt to format lib/src/server_response.dart.)

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and expected_response.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.0.0