πŸš€ zeba_academy_api_client

Enterprise‑grade REST and GraphQL API client for Flutter and Dart applications.

zeba_academy_api_client provides a powerful networking layer with interceptors, retry logic, caching, offline support, logging, file upload/download, and pagination helpers.

Designed for production apps, EdTech platforms, SaaS apps, and large Flutter projects.


✨ Features

βœ… REST API wrapper

βœ… GraphQL support

βœ… Interceptor system (similar to Dio)

βœ… Automatic retry logic

βœ… Token refresh handling

βœ… Centralized error handling

βœ… Request / response logging

βœ… Timeout configuration

βœ… In‑memory request caching

βœ… Offline‑ready architecture

βœ… File upload

βœ… File download

βœ… API mocking for testing

βœ… Pagination helpers


πŸ“¦ Installation

Add the dependency in your pubspec.yaml:

dependencies:
  zeba_academy_api_client: ^1.0.0

Then run:

flutter pub get

πŸš€ Basic Usage

import 'package:zeba_academy_api_client/zeba_academy_api_client.dart';

final client = ApiClient(
  config: ApiConfig(
    baseUrl: "https://jsonplaceholder.typicode.com",
  ),
);

final response = await client.get("/users");

print(response.data);

βš™οΈ Configuration

You can configure timeout, retries, headers and more.

final client = ApiClient(
  config: ApiConfig(
    baseUrl: "https://api.example.com",
    timeout: Duration(seconds: 15),
    maxRetries: 3,
  ),
);

πŸ” Authentication Interceptor

Interceptors allow modifying requests globally.

class AuthInterceptor extends ApiInterceptor {
  final String token;

  AuthInterceptor(this.token);

  @override
  Future<void> onRequest(RequestContext ctx) async {
    ctx.headers['Authorization'] = 'Bearer $token';
  }
}

Usage:

final client = ApiClient(
  config: ApiConfig(baseUrl: "https://api.example.com"),
  interceptors: [
    AuthInterceptor("your_token"),
  ],
);

πŸ“Š Logging Interceptor

Logs all requests and responses.

final client = ApiClient(
  config: ApiConfig(baseUrl: "https://api.example.com"),
  interceptors: [
    LoggingInterceptor(),
  ],
);

πŸ” Retry Logic

Automatic retries for failed network calls.

final client = ApiClient(
  config: ApiConfig(
    baseUrl: "https://api.example.com",
    maxRetries: 3,
  ),
);

🧠 Request Caching

Enable in‑memory caching.

final client = ApiClient(
  config: ApiConfig(baseUrl: "https://api.example.com"),
  cache: MemoryCache(),
);

πŸ“‘ GraphQL Support

Execute GraphQL queries easily.

final response = await client.graphql(
  query: """
  query GetUsers {
    users {
      id
      name
    }
  }
  """,
);

πŸ“€ File Upload

await client.uploadFile(
  endpoint: "/upload",
  filePath: "path/to/file.png",
);

πŸ“₯ File Download

await client.downloadFile(
  url: "/files/report.pdf",
  savePath: "downloads/report.pdf",
);

πŸ“„ Pagination Helper

Simplifies paginated APIs.

final page = await client.getPage(
  endpoint: "/users",
  page: 1,
  limit: 10,
);

πŸ§ͺ API Mocking

Useful for development and testing.

final client = ApiClient(
  config: ApiConfig(baseUrl: "https://api.example.com"),
  mockResponses: {
    "/users": [
      {"id": 1, "name": "Test User"}
    ]
  },
);

πŸ“± Example UI

This package includes an example Flutter app demonstrating:

β€’ API calls β€’ Loading state β€’ Error handling β€’ Response rendering


πŸ“Έ Screenshots

Example Flutter UI demonstrating API request, response rendering, and error handling using zeba_academy_api_client.

API Client Demo

Then reference the screenshot in pubspec.yaml.

screenshots:
  - description: API client demo
    path: screenshots/api_client_demo.png

🧩 Architecture

The package is structured using modular networking layers:

lib/
 β”œβ”€β”€ src/
 β”‚   β”œβ”€β”€ api_client.dart
 β”‚   β”œβ”€β”€ api_config.dart
 β”‚   β”œβ”€β”€ api_response.dart
 β”‚   β”œβ”€β”€ api_exception.dart
 β”‚   β”œβ”€β”€ interceptors/
 β”‚   β”œβ”€β”€ cache/
 β”‚   β”œβ”€β”€ graphql/
 β”‚   β”œβ”€β”€ pagination/
 β”‚   └── retry/

This architecture ensures the client is scalable, maintainable, and production ready.


πŸ§ͺ Testing

Run tests using:

flutter test

πŸ“œ License

This project is licensed under the GPL‑3.0 License.


🏫 Zeba Academy

Built with ❀️ for modern Flutter development and EdTech platforms.