-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from dart-lang/mit-mit-example
Add a small example
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}."); | ||
} | ||
} |