mobile_api 0.0.4+11 copy "mobile_api: ^0.0.4+11" to clipboard
mobile_api: ^0.0.4+11 copied to clipboard

mobile api package for moam digital system

mobile_api #

A Dart/Flutter package for REST and GraphQL API integration.

Features #

  • REST client with shared headers, JSON decoding, typed success/failure results, and one retry after token refresh
  • GraphQL client with typed list/detail helpers and refresh support
  • Secure token/cache helpers backed by flutter_secure_storage
  • Optional network connectivity checks
  • Multipart/form-data upload support
  • Optional logger endpoint for captured API errors

Getting started #

Add the package to your pubspec.yaml:

dependencies:
  mobile_api: ^0.0.4+11

Import it:

import 'package:mobile_api/mobile_api.dart';

Configuration #

final cache = ICacheRepoImpl();

final apiConfig = ApiConfig(
  apiUrl: Uri.parse('https://api.example.com'),
  marketplaceValue: 'ml',
  userAgentValue: 'mlApp',
  refreshTokenPath: '/api/accounts/refresh',
  loggerPath: '/logger',
  appCache: cache,
  checkNetwork: CheckNetwork(),
);

Tokens are read from CoreCacheKey.accessToken and CoreCacheKey.refreshToken.

await cache.saveAll(
  CacheKeyBundle.tokenPair(
    access: accessToken,
    refresh: refreshToken,
  ),
);

REST usage #

final httpApi = IHttpImpl(apiConfig: apiConfig);

final result = await httpApi.baseMethod<UserResponse, DefaultErrorResponse>(
  '/api/users/me',
  requestType: RequestType.get,
  dataFromJson: UserResponse.fromJson,
  errorFromJson: DefaultErrorResponse.fromJson,
);

switch (result) {
  case Success(value: final user):
    // use user
  case Failure(exception: final error):
    // handle error
}

GraphQL usage #

final graphQlApi = IGraphQlImpl(
  apiConfig: apiConfig.copyWith(
    apiUrl: Uri.parse('https://api.example.com/graphql'),
  ),
);

final result = await graphQlApi.queryList<UserResponse, DefaultErrorResponse>(
  path: '''
query users {
  users {
    pageInfo { hasNextPage }
    items { id name }
  }
}
''',
  field: 'users',
  dataFromJson: UserResponse.fromJson,
  errorFromJson: DefaultErrorResponse.fromJson,
);

Development certificates #

By default, the package uses normal platform certificate validation. For local development against a host with a self-signed certificate, set allowBadCertificates: true in ApiConfig. Do not enable it for production builds.

1
likes
0
points
39
downloads

Publisher

unverified uploader

Weekly Downloads

mobile api package for moam digital system

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, flutter, flutter_secure_storage, fresh_graphql, graphql, http, http_parser

More

Packages that depend on mobile_api