Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: recipes/dart_io/pkg_http/bin/adding_custom_headers.dart

Issue 99333012: The first few short pkg:http examples (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: recipes/dart_io/pkg_http/bin/adding_custom_headers.dart
diff --git a/recipes/dart_io/pkg_http/bin/adding_custom_headers.dart b/recipes/dart_io/pkg_http/bin/adding_custom_headers.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5fc73f158f89d8d7b971b362d0c491cbe5f97fba
--- /dev/null
+++ b/recipes/dart_io/pkg_http/bin/adding_custom_headers.dart
@@ -0,0 +1,14 @@
+import 'dart:convert';
+import 'package:http/http.dart' as http;
+
+void main() {
+ var url = 'https://api.github.com/users/dart-lang/repos';
+ http.get(url, headers : {'User-Agent': 'request'}).then((response) {
Søren Gjesse 2013/12/09 08:30:47 Shouldn't we put something like 'Dart/1.0 (My Dart
shailentuli 2013/12/11 04:07:52 Done.
+ var repos = JSON.decode(response.body);
+ for (var repo in repos) {
+ print("${repo['name']}, "
Søren Gjesse 2013/12/09 08:30:47 Maybe add some label text as well, e.g. "Repositor
shailentuli 2013/12/11 04:07:52 Added a little header explaining the categories.
+ "${repo['stargazers_count']} "
+ "${repo['forks_count']}");
+ }
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698