json_rest_client 0.1.2 copy "json_rest_client: ^0.1.2" to clipboard
json_rest_client: ^0.1.2 copied to clipboard

A small, dependency-light JSON HTTP client with typed exceptions, pluggable auth token storage, user-agent injection, and refresh-on-401 retry with a single-flight refresh lock.

example/main.dart

import 'package:json_rest_client/json_rest_client.dart';

/// In-memory [TokenStore] used by the example app.
///
/// A real app would read the token from secure storage instead.
class ExampleTokenStore implements TokenStore {
  /// Creates a store that returns [token] for every key.
  ExampleTokenStore({this.token});

  /// Token returned by [read]; `null` means no token is stored.
  String? token;

  @override
  Future<String?> read(String key) async => token;
}

/// Fetches a post from JSONPlaceholder and prints its title.
///
/// Run with `dart run example/main.dart`.
Future<void> main() async {
  final client = JsonRestClient(
    baseUrl: 'https://jsonplaceholder.typicode.com/',
    tokenStore: ExampleTokenStore(),
    userAgentProvider: () async => 'json_rest_client_example/0.1.0',
  );
  try {
    final post = await client.get<Map<String, dynamic>>('posts/1');
    print('Post #${post?['id']}: ${post?['title']}');
  } finally {
    client.close();
  }
}
0
likes
160
points
266
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A small, dependency-light JSON HTTP client with typed exceptions, pluggable auth token storage, user-agent injection, and refresh-on-401 retry with a single-flight refresh lock.

Repository (GitHub)
View/report issues

Topics

#http #rest #json #api #client

License

MIT (license)

Dependencies

http

More

Packages that depend on json_rest_client