smalljson 1.0.0 copy "smalljson: ^1.0.0" to clipboard
smalljson: ^1.0.0 copied to clipboard

Transparently decode SmallJson-encoded API responses with a drop-in Dio interceptor. Pairs with the nylo/smalljson Laravel package.

example/smalljson_example.dart

import 'package:dio/dio.dart';
import 'package:smalljson/smalljson.dart';

Future<void> main() async {
  final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'))
    ..interceptors.add(SmallJsonInterceptor());

  // The interceptor adds `X-Small-Json: pz` to every request. When the server
  // answers with application/vnd.smalljson+json, the body is decoded in place
  // — response.data is ordinary JSON data, exactly as if the server had sent
  // plain JSON.
  final response = await dio.get<Object?>('/users');
  print(response.data);

  // Manual decoding (websockets, cached blobs, …) works too:
  const envelope =
      '{"_sj":1,"m":"p","k":["id","name"],"b":[2,[0,1],[1,"Ada"],[2,"Grace"]]}';
  print(const SmallJsonCodec().decode(envelope));
}
0
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publishernylo.dev

Weekly Downloads

Transparently decode SmallJson-encoded API responses with a drop-in Dio interceptor. Pairs with the nylo/smalljson Laravel package.

Repository (GitHub)
View/report issues

Topics

#dio #json #compression #network #interceptor

License

MIT (license)

Dependencies

dio

More

Packages that depend on smalljson