ac_httpx_client 0.3.1 copy "ac_httpx_client: ^0.3.1" to clipboard
ac_httpx_client: ^0.3.1 copied to clipboard

HTTP1/2 client in the style of Dart's HttpClient with an integrated RFC-compliant private cache.

example/example.dart

// SPDX-FileCopyrightText: © 2026 Anthony Champagne <dev@anthonychampagne.fr>
//
// SPDX-License-Identifier: BSD-3-Clause

// ignore_for_file: avoid_print

import 'dart:convert';

import 'package:ac_httpx_client/ac_httpx_client.dart';

Future<void> main() async {
  final client = HttpxClient();

  // --- Simple GET request ---
  print('--- GET request ---');

  final request = client.createRequest(
    uri: Uri.parse('https://httpbin.org/get'),
    method: 'GET',
  );

  final response = await request.close();
  print('Status: ${response.status} ${response.statusText}');
  print('Content-Type: ${response.headers['content-type']}');

  final body = await response.fold<List<int>>(
    [],
    (buffer, chunk) => buffer..addAll(chunk),
  );
  final text = utf8.decode(body);
  print('Body (truncated): ${text.substring(0, text.length.clamp(0, 200))}');

  // --- POST request with JSON body ---
  print('\n--- POST request ---');

  final postRequest = client.createRequest(
    uri: Uri.parse('https://httpbin.org/post'),
    method: 'POST',
    headers: HttpxHeaders.fromMap({'content-type': 'application/json'}),
  );

  final payload = utf8.encode('{"message":"hello"}');
  await postRequest.write(payload);
  final postResponse = await postRequest.close();
  print('Status: ${postResponse.status} ${postResponse.statusText}');
  await postResponse.dispose();
}
1
likes
150
points
84
downloads

Documentation

API reference

Publisher

verified publisheranthonychampagne.fr

Weekly Downloads

HTTP1/2 client in the style of Dart's HttpClient with an integrated RFC-compliant private cache.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

ac_dart_essentials, async, collection, freezed_annotation, hive, http2, http_parser, mutex

More

Packages that depend on ac_httpx_client