Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JSON:API client and server for Dart/Flutter

License

NotificationsYou must be signed in to change notification settings

f3ath/json-api-dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';voidmain()async {/// Define the server's base URLfinal baseUri='http://localhost:8080';/// Use the standard recommended URL structure or implement your ownfinal 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_interopfinal 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 attributesfor (final resourcein response.collection) {final {'name': name,'red': red,'green': green,'blue': blue,      }= resource.attributes;print('${resource.type}:${resource.id}');print('$name - $red:$green:$blue');    }  }onRequestFailurecatch (e) {/// Catch error responsefor (final errorin 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.

Sponsor this project

    Packages

    No packages published

    Contributors7

    Languages


    [8]ページ先頭

    ©2009-2025 Movatter.jp