| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library client; | 5 library client; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 | 10 |
| 11 import 'base_client.dart'; | 11 import 'base_client.dart'; |
| 12 import 'base_request.dart'; | 12 import 'base_request.dart'; |
| 13 import 'io.dart' as io; | 13 import 'io.dart' as io; |
| 14 import 'io_client.dart'; | 14 import 'io_client.dart'; |
| 15 import 'response.dart'; | 15 import 'response.dart'; |
| 16 import 'streamed_response.dart'; | 16 import 'streamed_response.dart'; |
| 17 | 17 |
| 18 /// The interface for HTTP clients that take care of maintaining persistent | 18 /// The interface for HTTP clients that take care of maintaining persistent |
| 19 /// connections across multiple requests to the same server. If you only need to | 19 /// connections across multiple requests to the same server. If you only need to |
| 20 /// send a single request, it's usually easier to use [head], [get], [post], | 20 /// send a single request, it's usually easier to use [head], [get], [post], |
| 21 /// [put], or [delete] instead. | 21 /// [put], [patch], or [delete] instead. |
| 22 /// | 22 /// |
| 23 /// When creating an HTTP client class with additional functionality, you must | 23 /// When creating an HTTP client class with additional functionality, you must |
| 24 /// extend [BaseClient] rather than [Client]. In most cases, you can wrap | 24 /// extend [BaseClient] rather than [Client]. In most cases, you can wrap |
| 25 /// another instance of [Client] and add functionality on top of that. This | 25 /// another instance of [Client] and add functionality on top of that. This |
| 26 /// allows all classes implementing [Client] to be mutually composable. | 26 /// allows all classes implementing [Client] to be mutually composable. |
| 27 abstract class Client { | 27 abstract class Client { |
| 28 /// Creates a new client. | 28 /// Creates a new client. |
| 29 /// | 29 /// |
| 30 /// Currently this will create an [IOClient] if `dart:io` is available and | 30 /// Currently this will create an [IOClient] if `dart:io` is available and |
| 31 /// throw an [UnsupportedError] otherwise. In the future, it will create a | 31 /// throw an [UnsupportedError] otherwise. In the future, it will create a |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 /// If [body] is a Map, it's encoded as form fields using [encoding]. The | 82 /// If [body] is a Map, it's encoded as form fields using [encoding]. The |
| 83 /// content-type of the request will be set to | 83 /// content-type of the request will be set to |
| 84 /// `"application/x-www-form-urlencoded"`; this cannot be overridden. | 84 /// `"application/x-www-form-urlencoded"`; this cannot be overridden. |
| 85 /// | 85 /// |
| 86 /// [encoding] defaults to [UTF8]. | 86 /// [encoding] defaults to [UTF8]. |
| 87 /// | 87 /// |
| 88 /// For more fine-grained control over the request, use [send] instead. | 88 /// For more fine-grained control over the request, use [send] instead. |
| 89 Future<Response> put(url, {Map<String, String> headers, body, | 89 Future<Response> put(url, {Map<String, String> headers, body, |
| 90 Encoding encoding}); | 90 Encoding encoding}); |
| 91 | 91 |
| 92 /// Sends an HTTP PATCH request with the given headers and body to the given |
| 93 /// URL, which can be a [Uri] or a [String]. |
| 94 /// |
| 95 /// [body] sets the body of the request. It can be a [String], a [List<int>] |
| 96 /// or a [Map<String, String>]. If it's a String, it's encoded using |
| 97 /// [encoding] and used as the body of the request. The content-type of the |
| 98 /// request will default to "text/plain". |
| 99 /// |
| 100 /// If [body] is a List, it's used as a list of bytes for the body of the |
| 101 /// request. |
| 102 /// |
| 103 /// If [body] is a Map, it's encoded as form fields using [encoding]. The |
| 104 /// content-type of the request will be set to |
| 105 /// `"application/x-www-form-urlencoded"`; this cannot be overridden. |
| 106 /// |
| 107 /// [encoding] defaults to [UTF8]. |
| 108 /// |
| 109 /// For more fine-grained control over the request, use [send] instead. |
| 110 Future<Response> patch(url, {Map<String, String> headers, body, |
| 111 Encoding encoding}); |
| 112 |
| 92 /// Sends an HTTP DELETE request with the given headers to the given URL, | 113 /// Sends an HTTP DELETE request with the given headers to the given URL, |
| 93 /// which can be a [Uri] or a [String]. | 114 /// which can be a [Uri] or a [String]. |
| 94 /// | 115 /// |
| 95 /// For more fine-grained control over the request, use [send] instead. | 116 /// For more fine-grained control over the request, use [send] instead. |
| 96 Future<Response> delete(url, {Map<String, String> headers}); | 117 Future<Response> delete(url, {Map<String, String> headers}); |
| 97 | 118 |
| 98 /// Sends an HTTP GET request with the given headers to the given URL, which | 119 /// Sends an HTTP GET request with the given headers to the given URL, which |
| 99 /// can be a [Uri] or a [String], and returns a Future that completes to the | 120 /// can be a [Uri] or a [String], and returns a Future that completes to the |
| 100 /// body of the response as a String. | 121 /// body of the response as a String. |
| 101 /// | 122 /// |
| (...skipping 16 matching lines...) Expand all Loading... |
| 118 Future<Uint8List> readBytes(url, {Map<String, String> headers}); | 139 Future<Uint8List> readBytes(url, {Map<String, String> headers}); |
| 119 | 140 |
| 120 /// Sends an HTTP request and asynchronously returns the response. | 141 /// Sends an HTTP request and asynchronously returns the response. |
| 121 Future<StreamedResponse> send(BaseRequest request); | 142 Future<StreamedResponse> send(BaseRequest request); |
| 122 | 143 |
| 123 /// Closes the client and cleans up any resources associated with it. It's | 144 /// Closes the client and cleans up any resources associated with it. It's |
| 124 /// important to close each client when it's done being used; failing to do so | 145 /// important to close each client when it's done being used; failing to do so |
| 125 /// can cause the Dart process to hang. | 146 /// can cause the Dart process to hang. |
| 126 void close(); | 147 void close(); |
| 127 } | 148 } |
| OLD | NEW |