Giter VIP home page Giter VIP logo

ashtav / fetchly Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 331 KB

Fetchly is a lightweight Dart package designed to streamline your API interactions by simplifying the usage of the Dio HTTP client. It provides an easy-to-use, type-safe, and efficient wrapper around Dio, making your HTTP calls and response handling smooth and hassle-free.

License: MIT License

Kotlin 0.15% Swift 2.09% Objective-C 0.05% Dart 42.83% CMake 22.69% C++ 27.90% C 1.73% HTML 2.23% Batchfile 0.33%

fetchly's Introduction

Fetchly is a lightweight Dart package designed to streamline your API interactions, making the use of the Dio HTTP client simpler and more efficient. It offers an easy-to-use, type-safe, and efficient wrapper around Dio, ensuring your HTTP calls and response handling are smooth and hassle-free. Additionally, Fetchly enhances the development experience by displaying vital request information such as the path, method, duration, and payload, exclusively in development mode. This feature enables developers to easily monitor and understand the requests made within their application, aiding in effective debugging and development.

Usage

To use this plugin, add fetchly as a dependency in your pubspec.yaml file.

Example

void main() {
  Fetchly.init(
    baseUrl: 'https://dummyjson.com/',
    onRequest: (path, status, data){
      // listen request
    },
    onError: (e, s){
      // listen error
    },
    printType: PrintType.print // available: log, print, none
  );

  runApp(const MyApp());
}

Usage

To make API requests, extend the Fetchly class and define your methods like so:

import 'package:fetchly/fetchly.dart';

class TodoApi extends Fetchly {
  Future<ResHandler> getTodos() async => await get('todos');
}

In this code snippet, we're using Dart's mixin feature to create a reusable block of code named UseApi.

mixin Apis {
    TodoApi todoApi = TodoApi();
    // other api
}

class MyClass with Apis {
    Future getTodos() async {
        ResHandler res = await todoApi.getTodos();

        // to cancel request, use
        todoApi.cancel('todos'); // todos is path name
    }
}

Methods

Provide some methods that you can use

// The `init` method is used to initialize Fetchly with a baseUrl and callbacks for onRequest and onError.
Fetchly.init(); 

// The `setHeader` method is used to set headers such as Authorization.
// You can also use dio.setToken('your_token') to set a token.
Fetchly.setHeader({});

For more information and examples, see the example.

fetchly's People

Contributors

ashtav avatar

Stargazers

49241036 avatar  avatar  avatar  avatar

Watchers

Lucian avatar  avatar  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.