http_in_memory_web_api 0.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 35

http-in-memory-web-api

An in-memory web api for demos and tests.

Inspired by angular2-in-memory-web-api

Usage

A simple usage example:

import 'package:http_in_memory_web_api/http_in_memory_web_api.dart';

main() async {
  final http = new HttpClientInMemoryBackendService(data);

  final response = await http.get('app/heroes.json');
  print(response.body);
  print(response.statusCode);
  print(response.headers);
}

CreateDb data = () => {
  'heroes':[
    { "id": "1", "name": "Windstorm" },
    { "id": "2", "name": "Bombasto" },
    { "id": "3", "name": "Magneta" },
    { "id": "4", "name": "Tornado" }
  ]
};

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.1.0

  • feat: implementation of put method
  • feat: implementation of delete method

0.0.1

  • Initial version, created by Stagehand

example/main.dart

import 'dart:async';
import 'dart:convert';
import 'package:http_in_memory_web_api/http_in_memory_web_api.dart';

final HttpClientInMemoryBackendService http =
    new HttpClientInMemoryBackendService(data);

Future main() async {
  await _get();
  await _post();
  await _put();
  await _get();
  await _delete();
  await _get();
}

Future _get() async {
  final url = 'app/heroes';
  print('[GET] /$url');
  var response = await http.get(url);
  print(response.statusCode);
  print(response.headers);
  print(response.body);
}

Future _post() async {
  final url = 'app/heroes';
  print('[POST] /$url');
  final body = JSON.encode({'id': 5, 'name': 'Windstorm: the great'});
  var response = await http.post(url, body: body);
  print(response.statusCode);
  print(response.headers);
  print(response.body);
}

Future _put() async {
  final url = 'app/heroes/7';
  print('[PUT] /$url');
  final body = JSON.encode({'id': 7, 'name': 'Windstorm: the great'});
  var response = await http.put(url, body: body);
  print(response.statusCode);
  print(response.headers);
  print(response.body);
}

Future _delete() async {
  final url = 'app/heroes/4';
  print('[DELETE] /$url');
  var response = await http.delete(url);
  print(response.statusCode);
  print(response.headers);
  print(response.body);
}

CreateDb data = () => {
      'heroes': [
        {"id": 1, "name": "Windstorm"},
        {"id": 2, "name": "Bombasto"},
        {"id": 3, "name": "Magneta"},
        {"id": 4, "name": "Tornado"}
      ]
    };

1. Depend on it

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


dependencies:
  http_in_memory_web_api: "^0.2.1"

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_in_memory_web_api/http_in_memory_web_api.dart';
        
Version Uploaded Documentation Archive
0.2.1 Oct 10, 2016 Go to the documentation of http_in_memory_web_api 0.2.1 Download http_in_memory_web_api 0.2.1 archive
0.2.0 Jun 16, 2016 Go to the documentation of http_in_memory_web_api 0.2.0 Download http_in_memory_web_api 0.2.0 archive
0.1.0 Feb 16, 2016 Go to the documentation of http_in_memory_web_api 0.1.0 Download http_in_memory_web_api 0.1.0 archive
0.0.1 Feb 9, 2016 Go to the documentation of http_in_memory_web_api 0.0.1 Download http_in_memory_web_api 0.0.1 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: web

Primary library: package:http_in_memory_web_api/http_in_memory_web_api.dart with components: html.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 errors 7 hints.

    Strong-mode analysis of lib/src/in_memory_backend_service.dart failed with the following error:

    line: 171 col: 12
    Couldn't infer type parameter 'T'.\n\nTried to infer 'dynamic' for 'T' which doesn't work:\n Type parameter 'T' declared to extend 'num'.\nThe type 'dynamic' was inferred from:\n Parameter 'a' declared as 'T'\n but argument is 'int'.\n Parameter 'b' declared as 'T'\n but argument is 'dynamic'.\n\nConsider passing explicit type argument(s) to the generic.\n\n

    Run dartfmt to format lib/src/http_status_codes.dart.

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

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

  • Enable strong mode analysis.

    Strong mode helps you to detect bugs and potential issues earlier.Start your analysis_options.yaml file with the following:

    analyzer:
      strong-mode: true
    

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
browser ^0.10.0+2 0.10.0+3
http ^0.11.3+3 0.11.3+16
Transitive dependencies
async 2.0.6
charcode 1.1.1
collection 1.14.9
http_parser 3.1.1
path 1.5.1
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
test >=0.12.0 <0.13.0