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

Test HTTP clients using a snapshot of the request and response

example/lib/example.dart

import 'dart:convert';
import 'dart:io';

class UserClient {
  final Uri _endpoint;

  const UserClient(this._endpoint);

  Future<User> getById(final int id) async {
    final response = await HttpClient()
        .getUrl(_endpoint.resolve('/api/v1/users/$id'))
        .then((request) => request.close());

    final body = jsonDecode(await utf8.decodeStream(response));

    return User(
      id: body['id'],
      name: body['name'],
    );
  }
}

class User {
  final int id;
  final String name;

  const User({
    required this.id,
    required this.name,
  });
}
2
likes
140
points
22
downloads

Documentation

API reference

Publisher

verified publishersoftwarefreak.net

Weekly Downloads

Test HTTP clients using a snapshot of the request and response

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

collection

More

Packages that depend on http_client_test