|
6 | 6 | import java.io.InputStream; |
7 | 7 | import java.net.URI; |
8 | 8 | import java.util.Map; |
| 9 | +import java.util.function.BiConsumer; |
9 | 10 | import java.util.function.Consumer; |
10 | 11 |
|
11 | 12 | /** |
|
17 | 18 | */ |
18 | 19 | public interface HttpClient { |
19 | 20 |
|
20 | | - public interface HttpRequestBuilder { |
| 21 | + public interface HttpRequest { |
21 | 22 |
|
22 | 23 | public String getMethod(); |
23 | 24 |
|
24 | 25 | public URI getUri(); |
25 | 26 |
|
26 | | - public HttpRequestBuilder addHeader(String name, String value); |
| 27 | + public HttpRequest addHeader(String name, String value); |
27 | 28 |
|
28 | | - public HttpRequestBuilder addParameter(String name, String value); |
| 29 | + public HttpRequest addParameter(String name, String value); |
29 | 30 |
|
30 | | - public HttpRequestBuilder addFile(String name, File file); |
| 31 | + public HttpRequest addFile(String name, File file); |
31 | 32 |
|
32 | | - public HttpRequestBuilder addFile(String name, InputStream stream); |
| 33 | + public HttpRequest addFile(String name, InputStream stream); |
33 | 34 |
|
34 | 35 | /** |
35 | 36 | * Send the request to the server and return the response. |
36 | 37 | */ |
37 | 38 | public HttpResponse execute() throws IOException; |
38 | 39 |
|
39 | | - HttpResponse executeAsync(Consumer<? super HttpResponse> done, Consumer<? super HttpResponse> fail, |
40 | | - Consumer<? super HttpResponse> always); |
| 40 | + HttpResponse executeAsync(Consumer<? super HttpResponse> success, |
| 41 | + BiConsumer<? super HttpResponse, Throwable> failure, |
| 42 | + BiConsumer<? super HttpResponse, Throwable> always); |
41 | 43 | } |
42 | 44 |
|
43 | 45 | public interface HttpResponse extends Closeable { |
@@ -80,32 +82,32 @@ public default void close() throws IOException { |
80 | 82 | * Initialises the GET request builder. Usually they have no request body and |
81 | 83 | * parameters are passed in the URL query. |
82 | 84 | */ |
83 | | - public HttpRequestBuilder get(URI uri); |
| 85 | + public HttpRequest get(URI uri); |
84 | 86 |
|
85 | 87 | /** |
86 | 88 | * Initialises the GET request builder. They have no request body and parameters |
87 | 89 | * are passed in the URL query. They are identical to GET requests, the only |
88 | 90 | * difference is that the returned response contains headers only. |
89 | 91 | */ |
90 | | - public HttpRequestBuilder head(URI uri); |
| 92 | + public HttpRequest head(URI uri); |
91 | 93 |
|
92 | 94 | /** |
93 | 95 | * Initialises the POST request builder. Usually they contain data in the |
94 | 96 | * request body either as a urlencoded form, a multipart form or raw bytes. |
95 | 97 | * Currently, we only care about the multipart form. |
96 | 98 | */ |
97 | | - public HttpRequestBuilder post(URI uri); |
| 99 | + public HttpRequest post(URI uri); |
98 | 100 |
|
99 | 101 | /** |
100 | 102 | * Initialises the PUT request builder which construct the same way as POST. The |
101 | 103 | * only difference is the request method. |
102 | 104 | */ |
103 | | - public HttpRequestBuilder put(URI uri); |
| 105 | + public HttpRequest put(URI uri); |
104 | 106 |
|
105 | 107 | /** |
106 | 108 | * Initialises the DELETE request builder. The DELETE requests have no body and |
107 | 109 | * parameters are passed in the URL query, just like GET. |
108 | 110 | */ |
109 | | - public HttpRequestBuilder delete(URI uri); |
| 111 | + public HttpRequest delete(URI uri); |
110 | 112 |
|
111 | 113 | } |
0 commit comments