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

Side by Side Diff: pkg/http/README.md

Issue 89433002: Create a first-cut for a README for http package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: turn on docs for http package 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/http/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # An easy-to-use HTTP client.
Bob Nystrom 2013/11/26 23:06:38 Have you looked at the main library comment in htt
sethladd 2013/11/26 23:11:00 Done.
2
3 This package contains a set of high-level functions and classes that
4 make it easy to consume HTTP resources.
Bob Nystrom 2013/11/26 23:06:38 Nit, but can you word wrap these at 80 (or 79) col
sethladd 2013/11/26 23:11:00 Looks wrapped to me? Was it this line?
Bob Nystrom 2013/11/26 23:18:00 I should have been clearer. :) It looks like this
sethladd 2013/11/26 23:42:09 Done.
5
6 **NOTE:** This package only works for
7 server-side or command-line Dart applications.
Bob Nystrom 2013/11/26 23:06:38 It might help to mention that this uses "dart:io".
sethladd 2013/11/26 23:11:00 I added a mention of dart:io
8
9 ## Installing
10
11 See the [http package on pub][hosted] for installation instructions.
12
13 ## Reading text from a resource
14
15 Use the `read()` function to easily GET an HTTP or HTTPS resource.
16 The returned future completes with a String of the response body,
17 or completes with an error.
18
19 import 'package:http/http.dart' as http;
20
21 void main() {
22 http.read('https://www.example.com/').then((String contents) {
Bob Nystrom 2013/11/26 23:06:38 Ditch the type annotation on the lambda, here and
sethladd 2013/11/26 23:11:00 I have to respectfully disagree. Without the type
23 print(contents);
24 });
25 }
26
27 ## Reading bytes from a resource
28
29 Use the `readBytes()` function to GET a list of bytes from an HTTP or HTTPS
30 resource.
31
32 import 'package:http/http.dart' as http;
33
34 void main() {
35 http.read('https://www.example.com/binary').then((Uint8List bytes) {
36 print(contents.length);
37 });
38 }
39
40 ## Streaming bytes from a resource
41
42 Create a new `Client` to stream the bytes from a resource.
Bob Nystrom 2013/11/26 23:06:38 You might want to explain why they are creating a
sethladd 2013/11/26 23:11:00 I assume because there's no top-level convenience
Bob Nystrom 2013/11/26 23:18:00 That's a Nathan question. :)
43
44 import 'package:http/http.dart';
45
46 main() {
47 var client = new Client();
48
49 client.send(new Request('GET', Uri.parse('http://www.google.com/')))
50 .then((StreamedResponse resp) {
51 // After the headers have been received.
52 resp.stream.listen((List<int> bytes) {
53 print('Received ${bytes.length} bytes');
54 });
55 });
56 }
57
58 ## Posting to a resource
59
60 Use the `post()` function to easily POST a body to an HTTP or HTTPS resource.
61
62 import 'package:http/http.dart' as http;
63
64 var url = "http://example.com/whatsit/create";
65 http.post(url, body: {"name": "doodle", "color": "blue"})
66 .then((http.Response response) {
67 print("Response status: ${response.statusCode}");
68 print("Response body: ${response.body}");
69 });
70
71 http.read("http://example.com/foobar.txt").then(print);
72
73 ## HTTP methods
74
75 There are top-level functions for each of the main HTTP methods. Each
76 returns a `Future<Response>`.
77
78 * `get()`
79 * `post()`
80 * `delete()`
81 * `put()`
82 * `head()`
83
84 ## API docs
85
86 Coming soon.
87
88 ## Filing issues
89
90 Please file issues for the http package at [http://dartbug.com/new][bugs].
91
92 [hosted]: https://pub.dartlang.org/packages/http
93 [bugs]: http://dartbug.com/new
OLDNEW
« no previous file with comments | « no previous file | pkg/http/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698