Aus öffentlichen Paketdaten erstellte Orientierung.
japx ist ein leichtgewichtiges Flutter/Dart-Paket, das zum Parsen und Arbeiten mit JSON:API-strukturierten Daten entwickelt wurde. Es vereinfacht den Umgang mit Antworten von Servern, die die JSON:API-Spezifikation befolgen, und ermöglicht Entwicklern, Ressourcen, Beziehungen und Metadaten effizient zu extrahieren und zu verwalten. Das Paket ist für Leistung und Benutzerfreundlichkeit optimiert und daher ideal für Apps, die mit JSON:API-kompatiblen Backends arbeiten. Mit minimalem Overhead unterstützt japx alle wichtigen Plattformen, darunter Android, iOS, Web, macOS, Windows und Linux.
Anwendungsfälle
JSON:API-Antworten analysieren
Behandlung verschachtelter Beziehungen
Metadaten aus API-Payloads extrahieren
Apps mit JSON:API-Backends erstellen
Vereinfachung der API-Datenmodellierung
Hauptmerkmale
Leicht und schnell
Unterstützt die vollständige JSON:API-Struktur
Plattformübergreifende Kompatibilität
Einfach zu verwendende Parsing-Schnittstelle
Minimales Boilerplate
Geeignet für
Flutter-Anwendungen mit JSON:API
Entwickler, die eine effiziente API-Auswertung benötigen
Projekte, die eine saubere Datenumwandlung erfordern
Teams, die mit REST-APIs arbeiten, die die JSON:API-Spezifikation folgen
Anwendungen für mehrere Plattformen
Hinweise
Einhaltung des JSON:API-Formats erforderlich
Beschränkt auf JSON:API-spezifische Anwendungsfälle
Kein integrierter Cache oder Netzwerkschicht
Nicht geeignet für nicht-JSON:API-Datenstrukturen
Abhängig von der Server-seitigen JSON:API-Kompatibilität
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
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.