Skip to content

Latest commit

 

History

History
 
 

riptide-httpclient

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Riptide: HTTP Client

Feather

Javadoc Maven Central

Riptide: HTTP Client offers an alternative integration of Spring's RestTemplate (or ClientHttpRequestFactory) and Apache's HTTP Client.

Example

final Http http = Http.builder()
        .requestFactory(new ApacheClientHttpRequestFactory(client))
        .build();

Features

  • independent from Riptide: Core, i.e. it can be used with a plain RestTemplate
  • fixes several issues with Spring's HttpComponentsClientHttpRequestFactory:
    • preserve the underlying client's request config
    • releasing connections back to the pool after closing streams
    • aborts connection when the stream hasn't been consumed fully

Dependencies

  • Java 8

Installation

Add the following dependency to your project:

<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>riptide-httpclient</artifactId>
    <version>${riptide.version}</version>
</dependency>

Configuration

The majority of configuration is done on the underlying HttpClient:

CloseableHttpClient client = HttpClientBuilder.create()
        // TODO configure client here
        .build();

final Http http = Http.builder()
        .requestFactory(new ApacheClientHttpRequestFactory(client))
        .build();

What the ApacheClientHttpRequestFactory in addition offers two modes of operation:

new ApacheClientHttpRequestFactory(client, Mode.BUFFERING)
Streaming (default)
Streams request bodies directly to the server. This requires less memory but any serialization error would result in an invalid, partial request to the server.
Buffering
Buffers request bodies before sending anything to the server. This requires more memory but allows to catch serialization early without the server noticing.

The RestAsyncClientHttpRequestFactory implements ClientHttpRequestFactory as well as AsyncClientHttpRequestFactory and can therefore be used with both: RestTemplate and AsyncRestTemplate.

RestAsyncClientHttpRequestFactory factory = ...;

RestTemplate sync = new RestTemplate(factory);
AsyncRestTemplate async = new AsyncRestTemplate(factory);

Getting Help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.

Getting Involved/Contributing

To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change. For more details, check the contribution guidelines.