๐Ÿ›ฐ๏ธ API Sentinel

A structured, developer-friendly networking and debugging layer for Flutter.
api_sentinel provides a clean and consistent way to handle API requests, error mapping, and runtime debugging through an on-screen overlay.


โœจ Features

โœ… Unified API call interface via ApiService.instance.request()
โœ… Customizable callbacks for success, Dio exceptions, and general exceptions
โœ… Centralized error handling and message parsing
โœ… Floating on-screen debug overlay to visualize requests
โœ… Built with dio and get (GetX) for lightweight reactivity
โœ… Supports Android, iOS, and Web


๐Ÿ“ฆ Installation

Add this line to your pubspec.yaml:

dependencies:
  api_sentinel: ^0.0.4

Then run:

flutter pub get

๐Ÿง  Architecture Overview

The library is built around three core layers:

Layer Description
ApiService Handles all HTTP requests (GET, POST, PUT, PATCH, DELETE) through Dio.
ErrorHandler Converts all errors (network, timeout, response, etc.) into readable Failure objects.
DebugOverlay Shows all ongoing and past requests on top of your UI during runtime (toggleable).

โš™๏ธ Usage

1๏ธโƒฃ Initialize the Service

final api = ApiService(baseUrl: 'YOUR_BASE_URL');

2๏ธโƒฃ Make a Request

Each request is wrapped with ApiService.instance.request() This ensures that error handling, logging, and overlay integration all happen automatically.

await ApiService.instance.request(
  method: HttpMethod.get,
  url: 'SOME_REQUEST',
  onSuccess: (response) {
    print('โœ… Success: ${response.data}');
  },
  onCatchDioException: (error) {
    print('โŒ Dio Error: ${handleErrorMessage(error)}');
  },
  onCatchException: (error) {
    print('๐Ÿ’ฅ Exception: ${handleErrorMessage(error)}');
  },
);

This pattern applies to any HTTP method โ€” just change the method and url.


3๏ธโƒฃ Supported HTTP Methods

You can use all standard HTTP verbs through the HttpMethod enum:

enum HttpMethod { get, post, put, patch, delete }

๐Ÿงฉ Error Architecture

Error Type Source Failure Example
Connection Timeout Dio (-1) Connection timed out
Bad Request HTTP 400 Bad Request
Unauthorized HTTP 401 Unauthorized access
Forbidden HTTP 403 Access denied
Not Found HTTP 404 Resource not found
Server Error HTTP 500 Internal server error
Cancelled Dio CancelToken Request cancelled
Unknown Fallback Something went wrong

๐Ÿงฐ Debug Overlay

๐ŸงŠ Floating Draggable Widget

A persistent, draggable button gives quick access to real-time logs.

Stack(
  children: [
    // Your main widget
    MyApp(), 
    // Your debug overlay button
    const DebugOverlayWidget(),
  ]
)

Inside, youโ€™ll see:

  • A real-time log list for each request
  • Search and filter by method/status code
  • Tap any log to expand request/response JSON
  • Toggle between Tree View and Pretty JSON
  • Click to expand full-screen

๐ŸŒณ JSON Tree Viewer

Displays structured hierarchical JSON for nested inspection.

๐ŸŽจ Pretty JSON Viewer

Shows syntax-colored formatted JSON text.

๐Ÿ–ฅ Full-Screen View

Click the expand icon (๐Ÿ”) in the corner to open the full JSON view for better readability.

Whenever your app performs an API call through ApiService, it will appear in a floating overlay with:

  • Method type (GET/POST/PUT/PATCH/DELETE)
  • Status code
  • Response time
  • Response preview


๐Ÿงช Example Project

A complete example app is included under the example/ directory.

To run it:

cd example
flutter run

It includes a test page with colored buttons for:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE
  • 404 Error simulation

All using the ApiService and DebugOverlay.


๐Ÿ“š License

MIT License ยฉ 2025 Developed and maintained by Aref Yazdkhasti


๐Ÿ’ฌ Contribution

Contributions are welcome! If youโ€™d like to improve the debugging UI, extend the ErrorHandler, or support additional APIs, open a PR or issue.


๐Ÿงญ Future Plans

  • Response caching layer
  • Retry strategy for failed requests and 401 unauthenticated request
  • Filterable API session logs

API Sentinel โ€” Because understanding your API should be as clear as your code.