dio_api_version_interceptor 0.0.2 copy "dio_api_version_interceptor: ^0.0.2" to clipboard
dio_api_version_interceptor: ^0.0.2 copied to clipboard

A utility package for Dio. Can intercept response headers to check if app version is compatible with API by listening to a stream, or call a GET method on starting the app.

Installation #

    dependencies:
        dio_api_version_interceptor: [version]

Usage #

Import the library

import 'package:dio_api_version_interceptor/dio_api_version_interceptor.dart';

You can use an explicit call to the endpoint to check the version compatibility.

 final dio = Dio(BaseOptions(baseUrl: 'https://run.mocky.io'));
 return dio.checkCompatibilityMapped(
    path: '/v3/bb2dd989-d94a-46b8-9cdc-76d32a979dc3',
    appVersion: appVersion,
  );

Or you can use the Header Interceptor to check version on every response

 
 final headerResultController =
    StreamController<CompatibilityResult>;
 ...
 final interceptor = ApiVersionHeaderInterceptor(
    streamController: headerResultController,
    appVersion: appVersion,
    minSupportedVersion: VersionSupportType.minor,
  );
  dio = Dio(BaseOptions(baseUrl: 'https://run.mocky.io'))
    ..interceptors.add(interceptor);

  return headerResultController.stream;
0
likes
130
pub points
0%
popularity

Publisher

unverified uploader

A utility package for Dio. Can intercept response headers to check if app version is compatible with API by listening to a stream, or call a GET method on starting the app.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

dio, equatable

More

Packages that depend on dio_api_version_interceptor