jsonplaceholder 2.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • new55

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());

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>


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(id: 1);
  print('Post with id of 1 is: ${post.toString().replaceAll('\n', '')}');

  // POST Todo object

  // When creating objects like this,
  // the optional id parameter refers to the id assigned by the server.
  // Even when you assign a value, it will be ignored by the server.
  Todo todo = Todo(1, 'Make a library', true);
  Todo response = await api.postTodo(todo);
  // Server assigns an id to the Todo.
  print('ID of the Todo object created without an id is ${response.id}');

  Todo todoWithId = Todo(1, 'Assign custom id', false, 42);
  Todo responseWithId = await api.postTodo(todoWithId);
  // The id is not 42.
  print('ID of the Todo object created with an id is ${responseWithId.id}');

  // DELETE Photo object

  // The DELETE methods return true if the resource has successfully been deleted.
  bool result = await api.deletePhoto(id: 1);
    "Deleting Photo with id of 1 was ${result ? 'successful' : 'unsuccessful'}",

  // PATCH Album object

  // Create Album object matching the id.
  // Method returns the patched object.
  Album album = Album(1, 'title', 1);
  album = await api.patchAlbum(album);

  // Close the client.

Use this package as a library

1. Depend on it

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

  jsonplaceholder: ^2.0.0

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:jsonplaceholder/jsonplaceholder.dart';
Version Uploaded Documentation Archive
2.0.0 Mar 7, 2019 Go to the documentation of jsonplaceholder 2.0.0 Download jsonplaceholder 2.0.0 archive
1.1.2 Mar 3, 2019 Go to the documentation of jsonplaceholder 1.1.2 Download jsonplaceholder 1.1.2 archive
1.1.1 Mar 1, 2019 Go to the documentation of jsonplaceholder 1.1.1 Download jsonplaceholder 1.1.1 archive
1.1.0 Mar 1, 2019 Go to the documentation of jsonplaceholder 1.1.0 Download jsonplaceholder 1.1.0 archive
1.0.0 Mar 1, 2019 Go to the documentation of jsonplaceholder 1.0.0 Download jsonplaceholder 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14


Detected platforms: Flutter, web, other

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


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
http ^0.12.0 0.12.0+1
meta ^1.1.6 1.1.7
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
path 1.6.2
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6