Skip to content

Commit

Permalink
Merge pull request #219 from dart-lang/mit-mit-example
Browse files Browse the repository at this point in the history
Add a small example
  • Loading branch information
mit-mit committed Jan 8, 2019
2 parents ffe786a + 7aef285 commit 93ccc13
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions example/main.dart
@@ -0,0 +1,18 @@
import 'dart:convert' as convert;
import 'package:http/http.dart' as http;

main(List<String> arguments) async {
// This example uses the Google Books API to search for books about http.
// https://developers.google.com/books/docs/overview
var url = "https://www.googleapis.com/books/v1/volumes?q={http}";

// Await the http get response, then decode the json-formatted responce.
var response = await http.get(url);
if (response.statusCode == 200) {
var jsonResponse = convert.jsonDecode(response.body);
var itemCount = jsonResponse['totalItems'];
print("Number of books about http: $itemCount.");
} else {
print("Request failed with status: ${response.statusCode}.");
}
}

0 comments on commit 93ccc13

Please sign in to comment.