json_api_document 0.0.7 copy "json_api_document: ^0.0.7" to clipboard
json_api_document: ^0.0.7 copied to clipboard

discontinued
outdated

JSON API Document model

example/main.dart

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() {
  print(json.encode(createResponse()));
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

JSON API Document model

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on json_api_document