Skip to content

Commit 12044a9

Browse files
authored
Update README to match current behavior (#249)
Closes #240 - Remove the browser specific sections and caveats - these are no longer necessary to call out since this package uses config specific imports. - Use single quoted strings consistently for style. - Update samples to use async/await. - Update doc links to point to the pub site.
1 parent 4464890 commit 12044a9

File tree

2 files changed

+20
-45
lines changed

2 files changed

+20
-45
lines changed

README.md

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ A composable, Future-based library for making HTTP requests.
55

66
This package contains a set of high-level functions and classes that make it
77
easy to consume HTTP resources. It's platform-independent, and can be used on
8-
both the command-line and the browser. Currently the global utility functions
9-
are unsupported on the browser; see "Using on the Browser" below.
8+
both the command-line and the browser.
109

1110
## Using
1211

13-
The easiest way to use this library is via the top-level functions, although
14-
they currently only work on platforms where `dart:io` is available. They allow
12+
The easiest way to use this library is via the top-level functions. They allow
1513
you to make individual HTTP requests with minimal hassle:
1614

1715
```dart
1816
import 'package:http/http.dart' as http;
1917
20-
var url = "http://example.com/whatsit/create";
21-
http.post(url, body: {"name": "doodle", "color": "blue"})
22-
.then((response) {
23-
print("Response status: ${response.statusCode}");
24-
print("Response body: ${response.body}");
25-
});
18+
var url = 'http://example.com/whatsit/create';
19+
var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'});
20+
print('Response status: ${response.statusCode}');
21+
print('Response body: ${response.body}');
2622
27-
http.read("http://example.com/foobar.txt").then(print);
23+
print(await http.read('http://example.com/foobar.txt'));
2824
```
2925

3026
If you're making multiple requests to the same server, you can keep open a
@@ -33,29 +29,30 @@ If you do this, make sure to close the client when you're done:
3329

3430
```dart
3531
var client = new http.Client();
36-
client.post(
37-
"http://example.com/whatsit/create",
38-
body: {"name": "doodle", "color": "blue"})
39-
.then((response) => client.get(response.bodyFields['uri']))
40-
.then((response) => print(response.body))
41-
.whenComplete(client.close);
32+
try {
33+
var uriResponse = await client.post('http://example.com/whatsit/create',
34+
body: {'name': 'doodle', 'color': 'blue'});
35+
print(await client.get(uriResponse.bodyFields['uri']));
36+
} finally {
37+
client.close();
38+
}
4239
```
4340

4441
You can also exert more fine-grained control over your requests and responses by
4542
creating [Request][] or [StreamedRequest][] objects yourself and passing them to
4643
[Client.send][].
4744

48-
[Request]: https://www.dartdocs.org/documentation/http/latest/http/Request-class.html
49-
[StreamedRequest]: https://www.dartdocs.org/documentation/http/latest/http/StreamedRequest-class.html
50-
[Client.send]: https://www.dartdocs.org/documentation/http/latest/http/Client/send.html
45+
[Request]: https://pub.dartlang.org/documentation/http/latest/http/Request-class.html
46+
[StreamedRequest]: https://pub.dartlang.org/documentation/http/latest/http/StreamedRequest-class.html
47+
[Client.send]: https://pub.dartlang.org/documentation/http/latest/http/Client/send.html
5148

5249
This package is designed to be composable. This makes it easy for external
5350
libraries to work with one another to add behavior to it. Libraries wishing to
5451
add behavior should create a subclass of [BaseClient][] that wraps another
5552
[Client][] and adds the desired behavior:
5653

57-
[BaseClient]: https://www.dartdocs.org/documentation/http/latest/http/BaseClient-class.html
58-
[Client]: https://www.dartdocs.org/documentation/http/latest/http/Client-class.html
54+
[BaseClient]: https://pub.dartlang.org/documentation/http/latest/http/BaseClient-class.html
55+
[Client]: https://pub.dartlang.org/documentation/http/latest/http/Client-class.html
5956

6057
```dart
6158
class UserAgentClient extends http.BaseClient {
@@ -70,25 +67,3 @@ class UserAgentClient extends http.BaseClient {
7067
}
7168
}
7269
```
73-
74-
## Using on the Browser
75-
76-
The HTTP library can be used on the browser via the [BrowserClient][] class in
77-
`package:http/browser_client.dart`. This client translates requests into
78-
XMLHttpRequests. For example:
79-
80-
[BrowserClient]: https://www.dartdocs.org/documentation/http/latest/http.browser_client/BrowserClient-class.html
81-
82-
```dart
83-
import 'dart:async';
84-
import 'package:http/browser_client.dart';
85-
86-
main() async {
87-
var client = new BrowserClient();
88-
var url = '/whatsit/create';
89-
var response =
90-
await client.post(url, body: {'name': 'doodle', 'color': 'blue'});
91-
print('Response status: ${response.statusCode}');
92-
print('Response body: ${response.body}');
93-
}
94-
```

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http
2-
version: 0.12.0+1
2+
version: 0.12.1-dev
33
author: "Dart Team <[email protected]>"
44
homepage: https://github.com/dart-lang/http
55
description: A composable, cross-platform, Future-based API for making HTTP requests.

0 commit comments

Comments
 (0)