It's been a while since I've made any updates and wanted to let the community know what I've been working on in 8.1.4.  Currently in the snapshot release is an entirely new RestClient API!

The old RestClient API sort of grew organically as a 2nd-class citizen to the server-side API.  As such, it wasn't well tested and didn't fully take advantage of the existing Apache HttpClient APIs.  I was often finding bugs and functionality often duplicated what already existed in HttpClient.

The new API includes all the same functionality of the old, but with the following advantages:

  • Extends directly from the Apache HttpComponents and Apache HttpClient APIs instead of merely using them.
  • APIs are written for easy extension.
  • Adds fluent-style coding to HTTP calls including easy-to-use fluent assertions.
  • Adds support for multiple simultaneous languages (including universal language support).
  • Is nearly 100% unit tested.

Here's an example of a fluent call from client creation to HTTP request and handling:

Constructing clients for supporting multiple languages is now as easy as:

Parsers and serializers can be easily configured via convenience builder methods like so:

HTTP parts (headers, query/form-data parameters) now support dynamically changing values through Suppliers:

Full support for OpenAPI part schema serialization is provided on all HTTP parts using a simple syntax on requests:

...and responses:

Response bodies can now be processed multiple times:

This combined with a new powerful assertions API allows you to easily perform complex fluent calls:

For example, it's even possible to do complex assertions that involve parsing and serialization:

The new API still supports Remote proxy interfaces (but with some added new features):

Logging and debugging has been simplified:

...which produces the following console output:

The RestClient class extends directly from Apache HttpClient and so inherits the same functionality.  Fluent setters have been provided on the builder class to make using these existing features easy:

The RestClient class (and other classes) can be extended as well to provide any sort of customization needed:

Additionally, the two separate MockRest (for server side testing) and MockRemote (for remote interface testing) have been replaced with a single MockRestClient class that extends directly from RestClient which allows you to take full advantage of the new assertions APIs as part of your unit tests:

The MockRestClient class can also wrap instantiated beans which is particularly useful if you're using Spring Boot for deployment of your REST servlets:

The following shows how to test remote interfaces using the new unified API:

See the updated Javadocs for more information:

  • No labels