jsonrequest 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 47

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/jsonrequest

Use this package as a library #

1. Depend on it #

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

dependencies:
  jsonrequest: ^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:jsonrequest/jsonrequest.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 '../lib/jsonrequest.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:
  jsonrequest: ^0.1.2

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:jsonrequest/jsonrequest.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
85
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

We analyzed this package on Nov 22, 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:jsonrequest/jsonrequest.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

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+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6