Skip to content

Commit ed1aa39

Browse files
bfgslandelle
authored andcommitted
Added retrofit2 module. (AsyncHttpClient#1419)
1 parent b2c1803 commit ed1aa39

File tree

9 files changed

+1416
-0
lines changed

9 files changed

+1416
-0
lines changed

extras/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>rxjava</module>
2020
<module>rxjava2</module>
2121
<module>simple</module>
22+
<module>retrofit2</module>
2223
</modules>
2324

2425
<dependencies>

extras/retrofit2/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Async-http-client Retrofit2 Call Adapter
2+
3+
An `okhttp3.Call.Factory` for implementing async-http-client powered [Retrofit][1] type-safe HTTP clients.
4+
5+
## Download
6+
7+
Download [the latest JAR][2] or grab via [Maven][3]:
8+
9+
```xml
10+
<dependency>
11+
<groupId>org.asynchttpclient</groupId>
12+
<artifactId>async-http-client-extras-retrofit2</artifactId>
13+
<version>latest.version</version>
14+
</dependency>
15+
```
16+
17+
or [Gradle][3]:
18+
19+
```groovy
20+
compile "org.asynchttpclient:async-http-client-extras-retrofit2:latest.version"
21+
```
22+
23+
[1]: http://square.github.io/retrofit/
24+
[2]: https://search.maven.org/remote_content?g=org.asynchttpclient&a=async-http-client-extras-retrofit2&v=LATEST
25+
[3]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.asynchttpclient%22%20a%3A%22async-http-client-extras-retrofit2%22
26+
[snap]: https://oss.sonatype.org/content/repositories/snapshots/
27+
28+
## Example usage
29+
30+
```java
31+
// instantiate async-http-client
32+
AsyncHttpClient httpClient = ...
33+
34+
// instantiate async-http-client call factory
35+
Call.Factory callFactory = AsyncHttpClientCallFactory.builder()
36+
.httpClient(httpClient) // required
37+
.onRequestStart(onRequestStart) // optional
38+
.onRequestFailure(onRequestFailure) // optional
39+
.onRequestSuccess(onRequestSuccess) // optional
40+
.requestCustomizer(requestCustomizer) // optional
41+
.build();
42+
43+
// instantiate retrofit
44+
Retrofit retrofit = new Retrofit.Builder()
45+
.callFactory(callFactory) // use our own call factory
46+
.addConverterFactory(ScalarsConverterFactory.create())
47+
.addConverterFactory(JacksonConverterFactory.create())
48+
// ... add other converter factories
49+
// .addCallAdapterFactory(RxJavaCallAdapterFactory.createAsync())
50+
.validateEagerly(true) // highly recommended!!!
51+
.baseUrl("https://api.github.com/");
52+
53+
// time to instantiate service
54+
GitHub github = retrofit.create(Github.class);
55+
56+
// enjoy your type-safe github service api! :-)
57+
```

extras/retrofit2/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>async-http-client-extras-parent</artifactId>
7+
<groupId>org.asynchttpclient</groupId>
8+
<version>2.1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>async-http-client-extras-retrofit2</artifactId>
12+
<name>Asynchronous Http Client Retrofit2 Extras</name>
13+
<description>The Async Http Client Retrofit2 Extras.</description>
14+
15+
<properties>
16+
<retrofit2.version>2.3.0</retrofit2.version>
17+
<lombok.version>1.16.16</lombok.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.projectlombok</groupId>
23+
<artifactId>lombok</artifactId>
24+
<version>${lombok.version}</version>
25+
<scope>provided</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>com.squareup.retrofit2</groupId>
30+
<artifactId>retrofit</artifactId>
31+
<version>${retrofit2.version}</version>
32+
</dependency>
33+
34+
<!-- for tests -->
35+
<dependency>
36+
<groupId>com.squareup.retrofit2</groupId>
37+
<artifactId>converter-scalars</artifactId>
38+
<version>${retrofit2.version}</version>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.squareup.retrofit2</groupId>
44+
<artifactId>converter-jackson</artifactId>
45+
<version>${retrofit2.version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>com.squareup.retrofit2</groupId>
51+
<artifactId>adapter-rxjava</artifactId>
52+
<version>${retrofit2.version}</version>
53+
<scope>test</scope>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>com.squareup.retrofit2</groupId>
58+
<artifactId>adapter-rxjava2</artifactId>
59+
<version>${retrofit2.version}</version>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
</project>

0 commit comments

Comments
 (0)