jsonplaceholder 3.0.0

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

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

We analyzed this package on Aug 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

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

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

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

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

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

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.20 points)

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

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

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

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

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.20 points)

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

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

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

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

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 7 files with analysis or formatting issues. (-536.95 points)

Additional issues in the following files:

  • lib/src/model/company.dart (6 errors)
  • lib/src/model/geo.dart (6 errors)
  • lib/src/model/photo.dart (6 errors)
  • lib/src/model/post.dart (6 errors)
  • lib/src/model/todo.dart (6 errors)
  • lib/src/model/user.dart (6 errors)
  • lib/src/model/serializers.dart (2 errors)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
built_collection ^4.2.2 4.2.2
built_value ^6.5.0 6.7.0
http ^0.12.0 0.12.0+2
meta ^1.1.6 1.1.7
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
fixnum 0.10.9
http_parser 3.1.3
matcher 0.12.5
path 1.6.4
pedantic 1.8.0+1
quiver 2.0.5
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.4.0
built_value_generator ^6.5.0