hequest 0.0.2 copy "hequest: ^0.0.2" to clipboard
hequest: ^0.0.2 copied to clipboard

outdated

Simple and hackable request for dart. Built on top of the http package.

example/main.dart

import 'dart:convert';

import 'package:hequest/hequest.dart';

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) {
        return throw Exception('User not found');
      } else {
        throw Exception('Failed to load user');
      }
    } catch (e) {
      throw Exception('Error getting user');
    }
  }
}

void main() async {
  final hequest = Hequest(baseUrl: 'https://api.github.com');
  final githubApi = GithubApi(hequest);

  final user = await githubApi.getUser('teixeirazeus');
  // ignore: avoid_print
  print(user.toString());
}
1
likes
0
pub points
0%
popularity

Publisher

verified publisherthiagoteixeira.dev

Simple and hackable request for dart. Built on top of the http package.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on hequest