Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module>rxjava</module>
<module>rxjava2</module>
<module>simple</module>
<module>retrofit2</module>
</modules>

<dependencies>
Expand Down
57 changes: 57 additions & 0 deletions extras/retrofit2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Async-http-client Retrofit2 Call Adapter

An `okhttp3.Call.Factory` for implementing async-http-client powered [Retrofit][1] type-safe HTTP clients.

## Download

Download [the latest JAR][2] or grab via [Maven][3]:

```xml
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client-extras-retrofit2</artifactId>
<version>latest.version</version>
</dependency>
```

or [Gradle][3]:

```groovy
compile "org.asynchttpclient:async-http-client-extras-retrofit2:latest.version"
```

[1]: http://square.github.io/retrofit/
[2]: https://search.maven.org/remote_content?g=org.asynchttpclient&a=async-http-client-extras-retrofit2&v=LATEST
[3]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.asynchttpclient%22%20a%3A%22async-http-client-extras-retrofit2%22
[snap]: https://oss.sonatype.org/content/repositories/snapshots/

## Example usage

```java
// instantiate async-http-client
AsyncHttpClient httpClient = ...

// instantiate async-http-client call factory
Call.Factory callFactory = AsyncHttpClientCallFactory.builder()
.httpClient(httpClient) // required
.onRequestStart(onRequestStart) // optional
.onRequestFailure(onRequestFailure) // optional
.onRequestSuccess(onRequestSuccess) // optional
.requestCustomizer(requestCustomizer) // optional
.build();

// instantiate retrofit
Retrofit retrofit = new Retrofit.Builder()
.callFactory(callFactory) // use our own call factory
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
// ... add other converter factories
// .addCallAdapterFactory(RxJavaCallAdapterFactory.createAsync())
.validateEagerly(true) // highly recommended!!!
.baseUrl("https://api.github.com/");

// time to instantiate service
GitHub github = retrofit.create(Github.class);

// enjoy your type-safe github service api! :-)
```
63 changes: 63 additions & 0 deletions extras/retrofit2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>async-http-client-extras-parent</artifactId>
<groupId>org.asynchttpclient</groupId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<artifactId>async-http-client-extras-retrofit2</artifactId>
<name>Asynchronous Http Client Retrofit2 Extras</name>
<description>The Async Http Client Retrofit2 Extras.</description>

<properties>
<retrofit2.version>2.3.0</retrofit2.version>
<lombok.version>1.16.16</lombok.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'd rather not use lombok in there so coding style is consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can convert all the code to normal java code, but frankly i don't think it's worth it - some other open source projects, namely spring-cloud started using lombok 2-3 years ago and it seem to work for them very well.

So, do you want me to de-lombok the code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave Lombok there. But I don't think it will ever make it into main module.

</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>${retrofit2.version}</version>
</dependency>

<!-- for tests -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-scalars</artifactId>
<version>${retrofit2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<version>${retrofit2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava</artifactId>
<version>${retrofit2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava2</artifactId>
<version>${retrofit2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading