json_query_dio 0.1.0 copy "json_query_dio: ^0.1.0" to clipboard
json_query_dio: ^0.1.0 copied to clipboard

Thin Dio integration for json_query - pick/map fields straight off a Response.

json_query_dio #

A thin Dio integration for json_query: pick and map fields straight off a Response, instead of wrapping response.data yourself.

final response = await dio.get('/user');

final user = response.map<User>(
  {
    'id': '.data.user.id',
    'name': '.data.user.profile.name',
    'package': '.data.user.subscription.package.name',
  },
  User.fromJson,
);

What this package is #

Every method on json_query's JsonQuery class, mirrored as an extension on Response<dynamic>, applied to response.data:

response.get('.data.user.id');
response.pick({'id': '.data.user.id'});
response.pickList('.data.users', {'id': '.id'});
response.map<User>({'id': '.data.user.id'}, User.fromJson);
response.mapList<User>('.data.users', {'id': '.id'}, User.fromJson);

That's it. See the json_query README for the full query syntax and behavior — this package changes none of it, it just saves you writing JsonQuery(response.data) yourself.

What this package is not #

  • It does not wrap or replace Dio's HTTP behavior. Requests, headers, interceptors, retries, cancellation, and DioExceptions are entirely Dio's — this package never touches them.
  • It does not add a request+project+map combinator (e.g. a dio.getMapped(...) that fires the request for you). Fire the request with dio as usual, then call these extensions on the resulting Response.
  • Query and mapping errors are exactly json_query's (JsonQuerySyntaxException, JsonQueryAccessException, re-exported here for convenience) — never mixed with HTTP errors.

Install #

dependencies:
  json_query_dio: ^0.1.0
1
likes
160
points
59
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Thin Dio integration for json_query - pick/map fields straight off a Response.

Repository (GitHub)
View/report issues

Topics

#json #dio #http #mapping

License

MIT (license)

Dependencies

dio, json_query

More

Packages that depend on json_query_dio