Skip to content

Commit 4b676ae

Browse files
Update README.md
1 parent 60c58d8 commit 4b676ae

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

rxjava-contrib/rxjava-apache-http/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,55 @@ and for Ivy:
3232
<dependency org="com.netflix.rxjava" name="rxjava-apache-http" rev="x.y.z" />
3333
```
3434

35-
# Sample usage
35+
# Sample Usage
36+
37+
### Create a Request
38+
39+
```java
40+
ObservableHttp.createGet("http://www.wikipedia.com", httpClient).toObservable();
41+
ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), httpClient).toObservable();
42+
```
43+
44+
### Http Client
45+
46+
A basic default client:
47+
48+
```java
49+
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
50+
```
51+
52+
or a custom client with configuration options:
53+
54+
```java
55+
final RequestConfig requestConfig = RequestConfig.custom()
56+
.setSocketTimeout(3000)
57+
.setConnectTimeout(3000).build();
58+
final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
59+
.setDefaultRequestConfig(requestConfig)
60+
.setMaxConnPerRoute(20)
61+
.setMaxConnTotal(50)
62+
.build();
63+
```
64+
65+
### Normal Http GET
66+
67+
Execute a request and transform the `byte[]` reponse to a `String`:
68+
69+
```groovy
70+
ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), client)
71+
.toObservable()
72+
.flatMap({ ObservableHttpResponse response ->
73+
return response.getContent().map({ byte[] bb ->
74+
return new String(bb);
75+
});
76+
})
77+
.toBlockingObservable()
78+
.forEach({ String resp ->
79+
println(resp);
80+
});
81+
```
82+
83+
84+
85+
86+

0 commit comments

Comments
 (0)