File tree Expand file tree Collapse file tree 1 file changed +52
-1
lines changed
rxjava-contrib/rxjava-apache-http Expand file tree Collapse file tree 1 file changed +52
-1
lines changed Original file line number Diff line number Diff 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+
You can’t perform that action at this time.
0 commit comments