fetchly

Last updated:

0 purchases

fetchly Image
fetchly Images
Add to Cart

Description:

fetchly

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());
}

copied to clipboard
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');
}
copied to clipboard
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
}
}
copied to clipboard
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({});
copied to clipboard
Commands #
Fetchly provides a set of commands to manage your project files and directories effectively. These commands help you create, remove, and clean up files and directories within your app setup.
Generates a new file with the specified filename, such as configuration files or API endpoints.
dart run fetchly:create <filename>
copied to clipboard
Deletes the file with the specified filename, helping you maintain a clean project by removing unnecessary files.
dart run fetchly:remove <filename>
copied to clipboard
Clears out the API directory by removing old or unused API files, resetting the project’s API structure.
dart run fetchly:clean
copied to clipboard
Additional commands to generate the fromJsonList method in your model.
dart run fetchly:model <model-name>
copied to clipboard
For more information and examples, see the example.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.