json_api_document 0.0.7

  • README.md
  • Example
  • Installing
  • Versions
  • 66

JSON API Document model

Work in progress

The goal of this library is to provide a transparent way to build JSON API Documents.

  • A JSON API Document is an immutable value object which can be converted to JSON using JSON.encode()
  • All JSON API Documents are guaranteed to comply with JSON API v1.0


All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.



import 'dart:convert';
import 'package:json_api_document/json_api_document.dart';

Document createResponse() {
  final person_9 = Resource('people', '9',
      attributes: {
        'first-name': 'Dan',
        'last-name': 'Gebhardt',
        'twitter': 'dgeb'
      self: Link('http://example.com/people/9'));

  final comment_5 = Resource('comments', '5',
      attributes: {'body': 'First!'},
      relationships: {
        'author': Relationship.toOne(ResourceIdentifier('people', '2'))
      self: Link('http://example.com/comments/5'));

  final comment_12 = Resource('comments', '12',
      attributes: {'body': 'I like XML better'},
      relationships: {'author': Relationship.toOne(person_9.toIdentifier())},
      self: Link('http://example.com/comments/12'));

  final article = Resource('articles', '1',
      attributes: {'title': 'JSON API paints my bikeshed!'},
      relationships: {
        'author': Relationship.toOne(person_9.toIdentifier(),
            self: Link('http://example.com/articles/1/relationships/author'),
            related: Link('http://example.com/articles/1/author')),
        'comments': Relationship.toMany(
            [comment_5, comment_12].map((c) => c.toIdentifier()).toList(),
            self: Link('http://example.com/articles/1/relationships/comments'),
            related: Link('http://example.com/articles/1/comments'))
      self: Link('http://example.com/articles/1'));

  return Document.fromResourceList([article],
      self: Link('http://example.com/articles'),
      next: Link('http://example.com/articles?page[offset]=2'),
      last: Link('http://example.com/articles?page[offset]=10'),
      included: [person_9, comment_5, comment_12]);

void main() {

Use this package as a library

1. Depend on it

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

  json_api_document: ^0.0.7

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:json_api_document/json_api_document.dart';
Version Uploaded Documentation Archive
0.0.7 Aug 19, 2018 Go to the documentation of json_api_document 0.0.7 Download json_api_document 0.0.7 archive
0.0.6 Aug 15, 2018 Go to the documentation of json_api_document 0.0.6 Download json_api_document 0.0.6 archive
0.0.5 Mar 12, 2018 Go to the documentation of json_api_document 0.0.5 Download json_api_document 0.0.5 archive
0.0.4 Mar 12, 2018 Go to the documentation of json_api_document 0.0.4 Download json_api_document 0.0.4 archive
0.0.3 Mar 10, 2018 Go to the documentation of json_api_document 0.0.3 Download json_api_document 0.0.3 archive
0.0.2 Mar 8, 2018 Go to the documentation of json_api_document 0.0.2 Download json_api_document 0.0.2 archive
0.0.1 Mar 7, 2018 Go to the documentation of json_api_document 0.0.1 Download json_api_document 0.0.1 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 Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3


Detected platforms: Flutter, web, other

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


The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release.

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
json_matcher >=0.2.2
test 1.3.0