패키지, 저장소 및 앱 카테고리 검색

패키지 상세v8.1.0

json_api

프레임워크에 의존하지 않는 JSON:API 클라이언트 및 서버 구현입니다. JSON:API v1.0을 지원합니다 (https://jsonapi.org)

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4천
좋아요
37
Pub 점수
150

패키지 설치

flutter pub add json_api

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

JSON:API v1.0 사양을 준수하는 프레임워크에 관계없이 사용 가능한 Dart 구현입니다. 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.