Simple and hackable request for dart

Related tags

Templates dart http
Overview

banner Codacy BadgeLicense

Simple and hackable request for dart.

Installing

  1. Add dependencies to pubspec.yaml

    dependencies:
        hequest:
            git:
                url: https://github.com/teixeirazeus/hequest
  2. Run pub get.

    flutter pub get
  3. Import package.

    import 'package:hequest/hequest.dart';

Using

Hequest was created with simplicity in mind to handle multiple API requests.

You start by declaring an object of type Hequest and passing the baseUrl of your api.

final githubApi = Hequest(baseUrl: 'https://api.github.com');

GET

final response = await githubApi.get('/users/teixeirazeus');

POST

final response = await githubApi.post('/users/teixeirazeus', body: {
    'name': 'Zeus Teixeira',
    });

PUT

final response = await githubApi.put('/users/teixeirazeus', body: {
    'name': 'Zeus Teixeira',
    });

DELETE

final response = await githubApi.delete('/users/teixeirazeus');

JWT

All requests support sending jwt token.

To use to use the WithToken postfix and pass the token as a parameter.

final response = await githubApi.getWithToken('/users/teixeirazeus', token);

Tips

It is highly recommended that you use try catch to handle errors. Along with a larger abstraction with a class for each endpoint of your api.

class GithubApi {
  final Hequest _hequest;

  GithubApi(this._hequest);

  Future<Map> getUser(String username) async {
    try {
      final response = await _hequest.get('/users/$username');
      if (response.statusCode == 200) {
        return json.decode(response.body);
      } else if (response.statusCode == 404) {
        throw Exception('User not found');
      } else {
        throw Exception('Failed to load user');
      }
    } catch (e) {
      throw Exception('Error getting user');
    }
  }
}
final hequest = Hequest(baseUrl: 'https://api.github.com');
final githubApi = GithubApi(hequest);

final user = await githubApi.getUser('teixeirazeus');
print(user.toString());

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

You might also like...

A CLI tool to verify the test coverage of a pull request only, ignoring the rest of the project

A CLI tool to verify the test coverage of a pull request only, ignoring the rest of the project

This is a CI tool that analyzes the coverage rate of a pull request, ignoring the lines that were not changed in the PR. Motivation The coverage rate

Dec 15, 2022

Simple Dart package with build-in code generation. It simplifies and speedup creation of cache mechanism for dart classes.

Simple Dart package with build-in code generation. It simplifies and speedup creation of cache mechanism for dart classes.

Simple Dart package with build-in code generation. It simplifies and speedup creation of cache mechanism for dart classes.

Jan 2, 2023

Dart-dependency-injection - A simple example of how to use dependency injection with dart

This is a simple example of how to use dependency injection with dart. In this e

Feb 3, 2022

A beautiful, secure and simple authenticator app that supports multiple protocols and services. Free and open source. Written in Flutter and Dart.

A beautiful, secure and simple authenticator app that supports multiple protocols and services. Free and open source. Written in Flutter and Dart.

OpenAuth A beautiful, secure and simple authenticator app that supports multiple protocols and services. Free and open source. Written in Flutter and

Oct 5, 2022

Flutter simple image crop - A simple and easy to use flutter plugin to crop image on iOS and Android

Flutter simple image crop - A simple and easy to use flutter plugin to crop image on iOS and Android

Image Zoom and Cropping plugin for Flutter A simple and easy used flutter plugin to crop image on iOS and Android. Installation Add simple_image_crop

Dec 14, 2021

Mysql.dart - MySQL client for Dart written in Dart

Native MySQL client written in Dart for Dart See example directory for examples

Dec 29, 2022

Kc - A Simple App Solution for Calculation Fraction (Kali) size of a Lehenga. this is very useful for Fashion designers and tailors. Simple UI with best User Experience.

kc A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is yo

Jan 8, 2022

A simple project that will help you learn how to build a simple face filter app with Flutter and Deep AR

A simple project that will help you learn how to build a simple face filter app with Flutter and Deep AR

flutter_deepar This is a simple project that will help you learn how to build a simple face filter app with Flutter and Deep AR You can read an articl

Mar 11, 2022
Owner
Thiago da Silva Teixeira
This is our world now... The world of the electron and the switch, the beauty of the baud.
Thiago da Silva Teixeira
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

dio_http A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout

null 46 Dec 19, 2021
A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.

Language: English | 中文简体 dio A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File

Flutter中国开源项目 11.2k Jan 3, 2023
A sample app of using the image_picker + path_provider and permission_handler package to request permission and store photos on mobile

image_picker_example A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you sta

iang12 4 Apr 19, 2022
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

Flutter permission_handler plugin The Flutter permission_handler plugin is build following the federated plugin architecture. A detailed explanation o

Baseflow 1.7k Dec 31, 2022
Unloc customizations of the Permission plugin for Flutter. This plugin provides an API to request and check permissions.

Flutter Permission handler Plugin A permissions plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check perm

Unloc 1 Nov 26, 2020
A Flutter plugin to request the device unlock screen.

device_unlock A Flutter plugin to request the device unlock screen on Android and iOS. How does it work The following attempts and fallbacks are made:

Cíngulo 19 Sep 7, 2022
Http request inspector for Flutter application

Alice Alice is an HTTP Inspector tool for Flutter which helps debugging http requests. It catches and stores http requests and responses, which can be

Hau Tran 8 Dec 14, 2022
This repo contains a collection of permission related Flutter plugins which can be used to request permissions to access device resources in a cross-platform way.

Flutter Permission Plugins Deprecation Notice This repository has been replaced by the Flutter permission_handler plugin and will not longer be mainta

Baseflow 51 Dec 13, 2021
Hava Durumu Uygulaması - Temel Api Request

Hava Ne Durumda Bu uygulama temelde apilerle nasıl çalışılır, apiden veri nasıl GET edilir gibi işlemleri anlamak için yapılmıştır. Uygulama Fotoğrafl

Mehmet Ege Aydın 4 Jun 14, 2022
📖 A Guide for your first pull request

?? A Guide for your first pull request This project has been excluded by Hacktoberfest 2022 ✨ This project will help you to make your first pull reque

Dip Hire 27 Dec 2, 2022