パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v8.1.0

json_api

フレームワークに依存しない JSON:API クライアントおよびサーバーの実装。JSON:API v1.0 をサポートしています (https://jsonapi.org)

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1420
いいね数
37
Pub ポイント
150

パッケージをインストール

flutter pub add json_api

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

JSON:API v1.0 に準拠した、フレームワークに依存しないDart実装で、JSON:APIクライアントおよびサーバーの構築を可能にします。JSON:API仕様を使用して、アプリケーションとAPI間の構造的かつ標準的な通信を実現します。このパッケージはAndroid、iOS、Web、macOS、Windows、Linuxなどすべての主要プラットフォームをサポートしており、クロスプラットフォームプロジェクトに最適です。特定のUIフレームワークに縛られず、JSON:APIペイロードの解析、シリアル化、管理を効率的に行うためのツールを提供します。

用途

  • JSON:API v1.0 に準拠した RESTful API の構築
  • JSON:API を使用したバックエンドサービスとの統合
  • 複数のプラットフォームにまたがる統合データレイヤーの作成
  • API応答内の複雑な関係の処理
  • JSON:API 標準に基づくクライアント側キャッシュの実装

主な機能

  • 完全な JSON:API v1.0 対応
  • フレームワークに依存しない設計
  • クロスプラットフォーム対応
  • 堅牢なリクエスト/レスポンス処理
  • 組み込みリソースおよび関係のサポート
  • 簡単なシリアル化/逆シリアル化

適している対象

  • JSON:API エンドポイントを消費または提供するアプリを開発している開発者
  • 複数のプラットフォーム間で一貫したAPI構造を必要とするチーム
  • 標準化されたデータ交換形式を必要とするプロジェクト
  • DartでJSON:APIサーバーを実装するバックエンド開発者
  • 厳格なAPI契約要件を持つFlutterを使用するフロントエンドチーム

注意事項

  • JSON:API仕様の理解が必要です
  • 完全なフレームワークではない—既存のHTTPクライアントを補完
  • 仕様で定義された動作を超える限定的な組み込みエラー処理
  • 追加の検証または状態管理ライブラリと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

JSON:API Client and Server

TL;DR:

import 'package:http/http.dart' as http;
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));

  /// This is the Dart's standard HTTP client.
  /// Do not forget to close it in the end.
  final httpClient = http.Client();

  /// This is the interface which decouples this JSON:API implementation
  /// from the HTTP client.
  /// Learn more: https://pub.dev/packages/http_interop
  final httpHandler = httpClient.handleInterop;

  /// This is the basic JSON:API client. It is flexible but not very convenient
  /// to use, because you would need to remember a lot of JSON:API protocol details.
  /// We will use another wrapper on top of it.
  final jsonApiClient = Client(httpHandler);

  /// The [RoutingClient] is most likely the right choice.
  /// It is called routing because it routes the calls to the correct
  /// URLs depending on the use case. Take a look at its methods, they cover
  /// all the standard scenarios specified by the JSON:API standard.
  final client = RoutingClient(uriDesign, jsonApiClient);

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

    /// The fetched collection allows us to iterate over the resources
    /// and to look into their attributes
    for (final resource in response.collection) {
      final {
      'name': name,
      'red': red,
      'green': green,
      'blue': blue,
      } = resource.attributes;
      print('${resource.type}:${resource.id}');
      print('$name - $red:$green:$blue');
    }
  } on RequestFailure catch (e) {
    /// Catch error response
    for (final error in e.errors) {
      print(error.title);
    }
  }

  /// Free up the resources before exit.
  httpClient.close();
}

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

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。