fresh 0.0.1-dev+1 copy "fresh: ^0.0.1-dev+1" to clipboard
fresh: ^0.0.1-dev+1 copied to clipboard

outdated

A Dart HTTP Client with built-in token refresh. Fresh is built on top of package:http and manages tokens transparently.

Fresh

style: effective dart License: MIT


A Dart HTTP Client with built-in token refresh.

Overview #

Fresh is a package which attempts to simplify custom API authentication by integrating token refresh and caching directly into the client. Fresh is flexible and is intended to support custom token refresh mechanisms.

Usage #

Extend FreshClient #

class MyHttpClient extends FreshClient<OAuth2Token> {
  // Must provide a concrete implementation of `TokenStorage` to super.
  MyHttpClient() : super(InMemoryTokenStorage());

  @override
  Future<OAuth2Token> refreshToken(token, client) async {
    // Make a token refresh request using the current token
    // and the provided client and return a new token.
  }
}

Make Requests #

As requests are made, FreshClient will handle managing the token for you. Tokens will be refreshed as needed and requests will be automatically retried pending a successful refresh.

final httpClient = MyHttpClient();
final response = await httpClient.get(url, headers: headers);

Example #

See the example for a complete sample application using fresh which integrates with jsonplaceholder.

141
likes
0
pub points
80%
popularity

Publisher

verified publisherfelangel.dev

A Dart HTTP Client with built-in token refresh. Fresh is built on top of package:http and manages tokens transparently.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, meta

More

Packages that depend on fresh