Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dart/http_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:convert' as convert;

import 'package:http/http.dart' as http;

void main(List<String> arguments) async {
// This example uses the Google Books API to search
// for books about HTTP. For details, see
// https://developers.google.com/books/docs/overview
final url = Uri.https(
'www.googleapis.com',
'/books/v1/volumes',
{'q': '{http}'},
);

// Await the HTTP GET response, then decode the
// JSON data it contains.
final response = await http.get(url);

if (response.statusCode == 200) {
final jsonResponse = convert.jsonDecode(response.body);
final itemCount = jsonResponse['totalItems'];
print('Number of books about HTTP: $itemCount.');
} else {
print('Request failed with status: ${response.statusCode}.');
}
}