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

outdated

A rest client module for flutter.

flutter_rest_client #

A module that uses powerful http library dio for network calls.

Introduction #

flutter_rest_client is a network module that has been created seperately for easily maintaining code for dio. The usage of this module is pretty simple, just add the module to pubspec.yaml inside dependencies like following:


   flutter_rest_client:
     path: ./flutter_rest_client

One more configuration, flutter_rest_client is wrapped with dependency injection, which uses the project's getIt locator. Form the root of the project you must configure dependency first and then initialize with the following code:

  GetIt.I<AppConfig>().initialize(
    appName: 'appName',
    baseUrl: 'https://domain.com/v1/',
  );

AppConfig is part of project dependency, from which we use the baseUrl in our flutter_rest_client.

Basic Usage #

response = await httpHelper.request(RequestEndpoint(), BaseRequestModel(),headers: {});

headers parameter is optional, basic map set is setup in request interceptor.

Besides above uses, others are the basic functionality that uses the dio features.

Injection that need from the application getIt with injectable.

@Named('httpConfig')
@Singleton(as: IHttpConfig)
class HttpConfig implements IHttpConfig {
  final AppConfig _appConfig;
  final ISessionManager _iSessionManager;

  HttpConfig(this._appConfig, this._iSessionManager);

  @override
  int connectTimeout = 8000;

  @override
  String contentType = AppKeys.applicationJson;

  @override
  int receiveTimeout = 8000;

  @override
  String get baseUrl => _appConfig.baseUrl;

  @override
  int connectionTimeout = 8000;

  @override
  Future<String?> get token => _sessionManager.getToken();
}