json_api 6.0.1 copy "json_api: ^6.0.1" to clipboard
json_api: ^6.0.1 copied to clipboard

A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)

JSON:API Client and Server #

TL;DR:

import 'package:http_interop_http/http_interop_http.dart';
import 'package:json_api/client.dart';
import 'package:json_api/routing.dart';

void main() async {
  /// Define the server's base URL
  final baseUri = 'http://localhost:8080';

  /// Use the standard recommended URL structure or implement your own
  final uriDesign = StandardUriDesign(Uri.parse(baseUri));

  /// The [RoutingClient] is most likely the right choice.
  /// It has methods covering many standard use cases.
  final client = RoutingClient(uriDesign, Client(OneOffHandler()));

  try {
    /// Fetch the collection.
    /// See other methods to query and manipulate resources.
    final response = await client.fetchCollection('colors');

    final resources = response.collection;
    resources.map((resource) => resource.attributes).forEach((attr) {
      final name = attr['name'];
      final red = attr['red'];
      final green = attr['green'];
      final blue = attr['blue'];
      print('$name - $red:$green:$blue');
    });
  } on RequestFailure catch (e) {
    /// Catch error response
    for (var error in e.errors) {
      print(error.title);
    }
  }
}

This is a work-in-progress. You can help it by submitting a PR with a feature or documentation improvements.

34
likes
140
pub points
80%
popularity

Publisher

verified publisherkarapetov.com

A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http_interop, http_parser

More

Packages that depend on json_api