shelf_client 0.0.12 copy "shelf_client: ^0.0.12" to clipboard
shelf_client: ^0.0.12 copied to clipboard

HTTP client based on shelf package.

example/lib/example.dart

import 'dart:convert';

import 'package:shelf_client/shelf_client.dart';

Future<void> fetchRepositories(
  void Function(int totalCount) onOk,
  void Function(int statusCode) onElse,
) async {
  var client = Client();

  var response = await client.get(
    Uri(
      scheme: 'https',
      host: 'api.github.com',
      path: 'search/repositories',
      queryParameters: <String, String>{'q': 'Dart HTTP client'},
    ),
    headers: <String, String>{
      'Accept': 'application/vnd.github+json',
      'X-GitHub-Api-Version': '2022-11-28',
    },
  );

  if (response.statusCode == 200) {
    var stringBody = await response.readAsString();
    var jsonResponse = jsonDecode(stringBody) as Map<String, Object?>;
    var totalCount = jsonResponse['total_count'] as int;
    onOk(totalCount);
  } else {
    onElse(response.statusCode);
  }

  client.close();
}
0
likes
150
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

HTTP client based on shelf package.

Repository (GitHub)
View/report issues

Topics

#client #http #shelf

Documentation

API reference

License

MIT (license)

Dependencies

shelf, web

More

Packages that depend on shelf_client