Coder Social home page Coder Social logo

arfaz123 / http_handler Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 358 KB

HttpHandler is a Flutter package designed to simplify network API calls using the Dio HTTP client. It provides utility functions and customization options to streamline API request handling in your Flutter applications.

Home Page: https://pub.dev/packages/http_handler

License: Apache License 2.0

Dart 27.89% Kotlin 0.18% Swift 2.65% Objective-C 0.05% CMake 27.02% C++ 33.46% C 2.05% HTML 2.65% Ruby 4.04%
api dart-package dio flutter-package http

http_handler's Introduction

http_handler_banner_image

HttpHandler

Pub Version License


Introduction

HttpHandler is a Flutter package designed to simplify network API calls using the HTTP client. It provides utility functions and customization options to streamline API request handling in your Flutter applications.

Features

  • Simplified API calls with Http.
  • Customizable error and loading dialogs.
  • Network connectivity check.
  • Callback time measurement.

Table of Contents


Installation

To use HttpHandler in your Flutter project, add it as a dependency in your pubspec.yaml file:

dependencies:
  http_handler: <latest_version>

Then, run flutter pub get to install the package.


Usage

Import the Package

First, import the http_handler package in your Dart file:

import 'package:http_handler/http_handler.dart';

Create a HttpHandler Instance

Create an instance of HttpHandler by providing a http instance and other optional parameters:

  final httpHandler = HttpHandler(
  getBuildContext: context, // Required: Provide context
  customErrorDialog: MyCustomErrorDialog(), // Optional: Provide a custom error dialog widget
  customLoadingDialog: MyCustomLoadingDialog(), // Optional: Provide a custom loading dialog widget
  isCheckNetworkConnectivity: true, // Optional: Enable network connectivity check
  isAlertDialogs: true, // Optional: Show alert dialogs for errors
  isCallBackTime: true, // Optional: Measure API callback time (debug mode)
);

Replace MyCustomErrorDialog() and MyCustomLoadingDialog() with your actual custom error and loading dialog widgets if needed.

Make API Requests

To make an API request and handle responses, use the callAPI() method:

httpHandler.callAPI(
  serviceUrl: 'https://api.example.com/data',
  method: 'GET',
  success: (response) {
    // Handle successful response here
    print('API Request Successful');
    print(response.data);
  },
  error: (error) {
    // Handle error response here
    print('API Request Error');
    print(error);
  },
  showProcess: true, // Set to true to display a loading dialog
);

Example

You can find an example of how to use HttpHandler in the example folder of this package. To run the example, follow these steps:

  1. Clone this repository.
  2. Navigate to the example folder.
  3. Run flutter run to launch the example app.

Get in touch

If you have any questions, feel free to reach out:


Contributing

Contributions to the http_handler package are welcome! If you find a bug or want to add a new feature, feel free to open an issue or submit a pull request.

Contributors


License

This package is released under the MIT License. See the LICENSE file for details.


Feel free to explore the features of the HttpHandler package and customize it to suit your needs. If you have any questions or feedback, don't hesitate to reach out. Happy coding!

http_handler's People

Contributors

arfaz123 avatar nileshtanchak avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.