ht 0.1.0 copy "ht: ^0.1.0" to clipboard
ht: ^0.1.0 copied to clipboard

Fetch-style HTTP types and protocol abstractions for Dart.

example/main.dart

import 'dart:convert';

import 'package:ht/ht.dart';

Future<void> main() async {
  final request = Request.json(
    Uri.parse('https://api.example.com/tasks'),
    method: HttpMethod.post.value,
    body: {'title': 'Ship ht', 'priority': 'high'},
  );

  print('Request: ${request.method} ${request.url}');
  print('Request content-type: ${request.headers.get('content-type')}');
  print('Request body: ${await request.text()}');

  final response = Response(
    status: HttpStatus.created,
    body: jsonEncode({'ok': true, 'id': 'task_123'}),
    headers: Headers({'content-type': MimeType.json.toString()}),
  );

  print('Response status: ${response.status} ${response.statusText}');
  print('Response ok: ${response.ok}');
  print('Response body: ${await response.text()}');
}
0
likes
160
points
158
downloads

Publisher

verified publishermedz.dev

Weekly Downloads

Fetch-style HTTP types and protocol abstractions for Dart.

Repository (GitHub)
View/report issues

Topics

#http #fetch #web #types

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

async, http_parser, mime

More

Packages that depend on ht