jsonplaceholder 3.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 18

JSONPlaceholder-Dart #

A library that provides API bindings for JSONPlaceholder.

Usage #

A simple usage example:

import 'package:jsonplaceholder/json_placeholder.dart';

main(List<String> args) async {
  JSONPlaceholder api = JSONPlaceholder();
  var posts = api.getPosts();
  await for (Post post in posts) print(post.toString());
  api.close();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial Release

2.0.0 #

  • Replace the Stream requests with the counterparts that return Future<List>

3.0.0 #

  • Convert data classes into built_value types.
  • Convert List types into BuiltList

example/example.dart

import 'package:jsonplaceholder/jsonplaceholder.dart';

main(List<String> args) async {
  // Create client.
  JSONPlaceholder api = JSONPlaceholder();

  // GET Post objects
  var posts = await api.getPosts();
  var postsLength = await posts.length;
  print('Size of posts is $postsLength');

  // GET filtered Post objects
  var filteredPosts = await api.getPosts(userId: 1);
  var filteredPostsLength = await filteredPosts.length;
  print('Size of filtered posts by userId of 1 is $filteredPostsLength');

  // GET Post object of id
  var post = await api.getPost(1);
  print('Post with id of 1 is: ${post.toString().replaceAll('\n', '')}');

  // POST Todo object

  // Create objects with their builders.
  // id is nullable since the server will assign one.
  post = Post((b) => b
    ..title = 'Title'
    ..body = 'Body'
    ..userId = 1);
  var response = await api.postPost(post);
  print('ID of the Todo object created without an id is ${response.id}');

  // DELETE Photo object

  // The DELETE methods are void.
  await api.deletePost(post);

  // PATCH Album object

  // Create Album object matching the id.
  // Method returns the patched object.
  var album = Album().rebuild((b) => b
    ..title = "Title"
    ..userId = 1);
  album = await api.updateAlbum(album);
  print(album);

  // Close the client.
  api.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  jsonplaceholder: ^3.0.0

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:jsonplaceholder/jsonplaceholder.dart';
  
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]
90
Overall:
Weighted score of the above. [more]
18
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.2

Health issues and suggestions

Fix lib/src/model/address.dart. (-82.29 points)

Analysis of lib/src/model/address.dart failed with 6 errors, 1 hint, including:

line 10 col 6: Target of URI hasn't been generated: 'address.g.dart'.

line 12 col 50: 'dynamic' doesn't extend 'Builder<Address, dynamic>'.

line 12 col 50: The name 'AddressBuilder' isn't a type so it can't be used as a type argument.

line 15 col 28: Undefined class 'AddressBuilder'.

line 15 col 50: The name '_$Address' isn't a type and can't be used in a redirected constructor.

Fix lib/src/model/album.dart. (-82.29 points)

Analysis of lib/src/model/album.dart failed with 6 errors, 1 hint, including:

line 9 col 6: Target of URI hasn't been generated: 'album.g.dart'.

line 11 col 46: 'dynamic' doesn't extend 'Builder<Album, dynamic>'.

line 11 col 46: The name 'AlbumBuilder' isn't a type so it can't be used as a type argument.

line 14 col 26: Undefined class 'AlbumBuilder'.

line 14 col 46: The name '_$Album' isn't a type and can't be used in a redirected constructor.

Fix lib/src/model/comment.dart. (-82.29 points)

Analysis of lib/src/model/comment.dart failed with 6 errors, 1 hint, including:

line 9 col 6: Target of URI hasn't been generated: 'comment.g.dart'.

line 11 col 50: 'dynamic' doesn't extend 'Builder<Comment, dynamic>'.

line 11 col 50: The name 'CommentBuilder' isn't a type so it can't be used as a type argument.

line 14 col 28: Undefined class 'CommentBuilder'.

line 14 col 50: The name '_$Comment' isn't a type and can't be used in a redirected constructor.

Fix additional 8 files with analysis or formatting issues. (-545.20 points)

Additional issues in the following files:

  • lib/src/model/company.dart (6 errors, 1 hint)
  • lib/src/model/geo.dart (6 errors, 1 hint)
  • lib/src/model/photo.dart (6 errors, 1 hint)
  • lib/src/model/post.dart (6 errors, 1 hint)
  • lib/src/model/todo.dart (6 errors, 1 hint)
  • lib/src/model/user.dart (6 errors, 1 hint)
  • lib/src/model/serializers.dart (2 errors)
  • lib/src/jsonplaceholder.dart (16 hints)

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 (built_value).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
built_collection ^4.2.2 4.3.2
built_value ^6.5.0 6.8.2 7.0.8
http ^0.12.0 0.12.0+4
meta ^1.1.6 1.1.8
Transitive dependencies
analyzer 0.38.5 0.39.4
analyzer_plugin 0.2.1
args 1.5.2
async 2.4.0
build 1.2.2
build_config 0.4.1+1
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
fixnum 0.10.11
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
http_parser 3.1.3
js 0.6.1+1
json_annotation 3.0.1
kernel 0.3.27 0.3.29
logging 0.11.4
matcher 0.12.6
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.2
pubspec_parse 0.1.5
quiver 2.1.2+1
source_gen 0.9.4+6 0.9.4+7
source_span 1.6.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_runner ^1.4.0
built_value_generator ^6.5.0 6.8.2 7.0.8