networkjson 0.1.5

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

Network JSON Request package.

the package consists of JsonObject and JsonArray and handlers to get JsonArray from objects and JsonObject from arrays the most important part of this package is the ability to get async json directly from network calls it implements async GET and POST request simply by calling its network handlers

On Dart Packages : https://pub.dartlang.org/packages/networkjson

Use this package as a library

1. Depend on it

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

dependencies:
  networkjson: ^0.1.1

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:networkjson/networkjson.dart';

Getting Started

GET Request

Plain Request
Future<JsonObject> futureJson = JsonObject.get("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"});

it has options to provide query parameters and headers

Using with FutureBuilder
FutureBuilder<JsonObject>(
  future: JsonObject.get("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"});
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      JsonArray list = snapshot.data.array("list");
      ListView lv = ListView.builder(
          padding: new EdgeInsets.all(8.0),
          itemExtent: 100.0,
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index) {
            JsonObject json = list.object(index);
            return Text(json["key"]);
          }
      );
      return lv;
    } else if (snapshot.hasError) {
      return Text("${snapshot.error}");
    }
    return CircularProgressIndicator();
  },
)

POST Request

Plain Request
Future<JsonObject> futureJson = JsonObject.post("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"}, coding: PostCoding.JSON);

it has options to provide post parameters and headers the parameter encoding could be three types :

PostCoding.UrlEncoded //url ecoded parameter encoding with 'application/json' Content-Type
PostCoding.JSON // json encoded parameter encoding with 'application/x-www-form-urlencoded' Content-Type
PostCoding.Form //post form encoding
Using with FutureBuilder
FutureBuilder<JsonObject>(
  future: JsonObject.post("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"}, coding: PostCoding.JSON);
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      JsonArray list = snapshot.data.array("list");
      ListView lv = ListView.builder(
          padding: new EdgeInsets.all(8.0),
          itemExtent: 100.0,
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index) {
            JsonObject json = list.object(index);
            return Text(json["key"]);
          }
      );
      return lv;
    } else if (snapshot.hasError) {
      return Text("${snapshot.error}");
    }
    return CircularProgressIndicator();
  },
)

[0.1.5] - Release Date : 2018-09-13

  • added plain dart example

[0.1.4] - Release Date : 2018-09-13

  • removed flutter dependency

[0.1.3] - Release Date : 2018-09-13

  • changed description

[0.1.2] - Release Date : 2018-09-13

  • added install guide to readme

[0.1.1] - Release Date : 2018-09-13

  • changed author and homepage parameters

[0.1.0] - Release Date : 2018-09-13

  • added json object and array manipulation and network calls

example/example.dart

import 'dart:async';

import 'package:networkjson/networkjson.dart';

void main() {
  Future<JsonObject> jsonRequest = JsonObject.get("https://jsonplaceholder.typicode.com/todos/1");
  jsonRequest.then((json) {
    print(json["title"]);
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  networkjson: ^0.1.5

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:networkjson/networkjson.dart';
  
Version Uploaded Documentation Archive
0.1.5 Sep 13, 2018 Go to the documentation of networkjson 0.1.5 Download networkjson 0.1.5 archive
0.1.4 Sep 13, 2018 Go to the documentation of networkjson 0.1.4 Download networkjson 0.1.4 archive
0.1.3 Sep 13, 2018 Go to the documentation of networkjson 0.1.3 Download networkjson 0.1.3 archive
0.1.2 Sep 13, 2018 Go to the documentation of networkjson 0.1.2 Download networkjson 0.1.2 archive
0.1.1 Sep 13, 2018 Go to the documentation of networkjson 0.1.1 Download networkjson 0.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
48
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]
74
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
http ^0.11.3+17 0.11.3+17 0.12.0
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6