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

Http encapsulation to parse easily

HttpX #

HttpX is a package which aims to facilitate the use of the http package

Features #

HttpX parse http response in an easy way.

HttpX can manage the following methods :

  • GET
  • POST
  • PUT
  • DELETE

Usage #

import 'package:http_xtra/http_xtra.dart';

abstract class Api {
  static final HttpXtra client = HttpXtra(baseUrl: "https://my-endpoint.com");

  static Future<bool> isUp() => client.get<bool, String>(
        "/health",
        parser: (value) => value == "Up",
      );

  static Future<void> login() =>
      client.post<Map<String, dynamic>, Map<String, dynamic>>(
        "/login",
        body: {
          "email": "my-email",
          "password": "my-password",
        },
      ).then((tokens) => client.setAuthorization(tokens['accessToken']));

  static Future<Map<String, dynamic>> me() => client.get("/me");
}

void main() async {
  final bool isUp = await Api.isUp();

  if (isUp == false) return;

  await Api.login();

  final Map<String, dynamic> me = await Api.me();

  print(me);
}
2
likes
0
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

Http encapsulation to parse easily

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http

More

Packages that depend on http_xtra