dio_api_kit 1.0.2 copy "dio_api_kit: ^1.0.2" to clipboard
dio_api_kit: ^1.0.2 copied to clipboard

A lightweight, backend-agnostic API layer built on top of Dio with configurable success handling, centralized error management, and clean architecture support.

dio_api_kit #

A lightweight, flexible, and backend-agnostic API layer built on top of Dio.

dio_api_kit provides:

  • Centralized Dio initialization
  • Clean API service abstraction
  • Generic API response model
  • Configurable success resolver
  • Unified API error handling
  • Backend-independent parsing

โœจ Why dio_api_kit? #

Most APIs return responses in different formats:

  • status: true
  • status: 200
  • status: "success"
  • success: 1

Instead of hardcoding response assumptions, dio_api_kit allows you to define how success is determined โ€” making it completely backend-agnostic.


๐Ÿ“ฆ Installation #

Add to your pubspec.yaml:

dependencies:
  dio_api_kit: ^1.*.*

๐Ÿš€ Getting Started #

1๏ธโƒฃ Initialize at App Startup

Call this once (e.g., in main()):

DioApiKit.initialize(
  baseUrl: "https://api.example.com",
  apiConfig: ApiConfig(
    isSuccess: (status) => status == true || status == 200,
  ),
  interceptors: [
    LogInterceptor(responseBody: true),
  ],
);

2๏ธโƒฃ Make an API Call

Example repository usage:

final user = await APIWrapper.handleApiCall<User>(
  request: () async {
    final response = await DioApiKit.api.get<Map<String, dynamic>>(
      path: '/user',
    );

    return ApiResponse<User>.fromJson(
      response.data!,
      statusExtractor: (json) => json['status'],
      messageExtractor: (json) => json['message'],
      dataParser: (data) => User.fromJson(data),
    );
  },
  onError: (message) {
    print(message);
  },
);

๐Ÿ— Architecture Overview #

1๏ธโƒฃ DioApiKit

  • Initializes Dio
  • Injects interceptors
  • Sets base options
  • Initializes APIWrapper

2๏ธโƒฃ APIService

Thin wrapper around Dio.

Provides:

  • get
  • post
  • put
  • delete
  • patch

No business logic included.

3๏ธโƒฃ ApiResponse

Generic, backend-agnostic response model.

You provide:

  • statusExtractor
  • messageExtractor
  • dataParser

This avoids coupling to any backend format.

4๏ธโƒฃ APIWrapper

Handles:

  • Success validation
  • Error propagation
  • Typed data return
  • Boilerplate removal

๐ŸŽฏ Design Goals

  • Backend-agnostic
  • Strongly typed
  • Testable
  • Clean architecture friendly
  • Minimal boilerplate
  • Easily extendable

๐Ÿงฉ Example Success Resolver

ApiConfig(
  isSuccess: (status) {
    if (status is bool) return status;
    if (status is int) return status >= 200 && status < 300;
    if (status is String) return status.toLowerCase() == "success";
    return false;
  },
);

๐Ÿ” Interceptors Support

You can inject any Dio interceptors:

interceptors: [
  LogInterceptor(),
  YourAuthInterceptor(),
]

๐Ÿงช Testing

Because APIService is injected, you can easily:

  • Mock Dio
  • Mock ApiResponse
  • Test repositories independently

๐Ÿ“„ License

MIT License


---

# ๐Ÿ“œ MIT License (LICENSE file)

Create a file named `LICENSE` in your root:

```txt
MIT License

Copyright (c) 2026 ASHISH1317

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1
likes
160
points
239
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight, backend-agnostic API layer built on top of Dio with configurable success handling, centralized error management, and clean architecture support.

Repository (GitHub)
View/report issues

Topics

#dio #networking #api #http #clean-architecture

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter

More

Packages that depend on dio_api_kit