http_in_memory_web_api 0.2.1

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

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"}
      ]
    };

Use this package as a library

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
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
0
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

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0