japx는 JSON:API 구조화된 데이터를 파싱하고 작업하기 위해 설계된 가벼운 Flutter/Dart 패키지입니다. JSON:API 사양을 따르는 서버에서 오는 응답을 처리하는 과정을 단순화하여 개발자가 리소스, 관계 및 메타데이터를 효율적으로 추출하고 관리할 수 있도록 합니다. 성능과 사용 편의성에 최적화되어 있으며, JSON:API 호환 백엔드와 통합되는 앱에 이상적입니다. 최소한의 오버헤드로 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다.
사용 사례
JSON:API 응답 파싱
중첩된 관계 처리
API 페이로드에서 메타데이터 추출
JSON:API 백엔드로 앱 만들기
API 데이터 모델링 간소화
주요 기능
경량이고 빠름
완전한 JSON:API 구조를 지원합니다
크로스 플랫폼 호환성
사용이 간편한 파싱 인터페이스
최소한의 보일러플레이트
적합한 대상
JSON:API를 사용하는 Flutter 앱
효율적인 API 파싱이 필요한 개발자
정제된 데이터 변환을 필요로 하는 프로젝트
JSON:API 사양을 따르는 REST API를 사용하는 팀
다중 플랫폼을 대상으로 하는 앱
고려 사항
JSON:API 형식 준수 필요
JSON:API 전용 사용 사례에 한정
내장 캐시 또는 네트워크 계층 없음
JSON:API 데이터 구조가 아닌 경우 적합하지 않습니다
서버 측 JSON:API 호환성에 따라 달라짐
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Flutter Japx - JSON:API Decoder/Encoder
Lightweight [JSON:API][1] parser that flattens complex [JSON:API][1] structure and turns it into simple JSON and vice versa.
It works by transferring Map<String, dynamic> to Map<String, dynamic>, so you can use json_serializable or any other object mapping tool that you prefer.
For decoding the API responses use function Japx.decode(Map<String, dynamic> jsonApi, {String includeList}) which returns flattened JSON.
Include list is an optional parameter and it is used for deserializing JSON:API relationships.
For encoding use function Japx.encode(Object json, {Map<String, dynamic> additionalParams}) which will return a JSON with JSON:API format.
{"data":[{"type":"articles","id":"1","attributes":{"title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"},"relationships":{"author":{"data":{"id":"42","type":"people"}}}}],"included":[{"type":"people","id":"42","attributes":{"name":"John","age":80,"gender":"male"}}]}
Parsed JSON:
{"data":[{"type":"articles","id":"1","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z","author":{"type":"people","id":"42","name":"John","age":80,"gender":"male"}}]}
Decoding additional info
Response:
{"data":[{"type":"articles","id":"3","attributes":{"title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"}}],"meta":{"total-pages":13},"links":{"self":"http://example.com/articles?page[number]=3&page[size]=1","first":"http://example.com/articles?page[number]=1&page[size]=1","prev":"http://example.com/articles?page[number]=2&page[size]=1","next":"http://example.com/articles?page[number]=4&page[size]=1","last":"http://example.com/articles?page[number]=13&page[size]=1"},"additional":{"info":"My custom info"}}
Parsed JSON:
{"data":[{"type":"articles","id":"3","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"}],"meta":{"total-pages":13},"links":{"self":"http://example.com/articles?page[number]=3&page[size]=1","first":"http://example.com/articles?page[number]=1&page[size]=1","prev":"http://example.com/articles?page[number]=2&page[size]=1","next":"http://example.com/articles?page[number]=4&page[size]=1","last":"http://example.com/articles?page[number]=13&page[size]=1"},"additional":{"info":"My custom info"}}
{"type":"articles","id":"1","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z","author":{"type":"people","id":"42","name":"John","age":80,"gender":"male","article":{"type":"articles","id":"1","title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z","author":{"type":"people","id":"42","name":"John","age":80,"gender":"male"}}}}
Encode result:
{"data":{"type":"articles","id":"1","attributes":{"title":"JSON API paints my bikeshed!","body":"The shortest article. Ever.","created":"2015-05-22T14:56:29.000Z","updated":"2015-05-22T14:56:28.000Z"},"relationships":{"author":{"data":{"id":"42","type":"people"}}}}}
Simple project with mocked API can be found in this repository. Clone the repository, set the main.dart as an application starting point and run the project.
Usage with JsonSerializable
This package can be implemented as a simple layer into your exisiting stack. For example, if you use JsonSerializable, you can do it like this:
We believe that the community can help us improve and build better a product.
Please refer to our contributing guide to learn about the types of contributions we accept and the process for submitting them.
To ensure that our community remains respectful and professional, we defined a code of conduct that we expect all contributors to follow.
We appreciate your interest and look forward to your contributions.
License
Copyright 2024 Infinum
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.