HttpBuilder-NG

HttpBuilder-NG is a modern Groovy DSL for making HTTP requests. It requires Java 8 and a modern version of Groovy. It is built against Groovy 2.4.x, but it doesn't make any assumptions about which version of Groovy you are using. The main goal of HttpBuilder-NG is to allow you to make http requests in a natural and readable way. See the User Guide for more details.

Features

Support for GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS, TRACE request methods

Equally usable with Groovy DSL and Java 8 functional interfaces (also works well in Kotlin)

Multiple client implementations (core-Java, Apache, OkHttp)

HTTPS support (with ability to ignore SSL issues)

Content compression

Multipart request/response support

BASIC and DIGEST authentication support

Support for client-implementation specific configuration

Support for configuring client proxies

Artifacts

There are three client implementations available, as described below:

Name Description core The default implementation based on the core Java `HttpURLConnection' class. This library also includes all the common library components used by other client implementations. apache Client implementation based on the Apache HttpComponents client. okhttp Client implementation based on the OkHttp client library.

The library artifacts are available on Bintray and Maven Central. For Gradle, add the following to your build:

compile 'io.github.http-builder-ng:http-builder-ng-[library-name]:1.0.4'

Similarly for Maven add:

<dependency> <groupId>io.github.http-builder-ng</groupId> <artifactId>http-builder-ng-[library-name]</artifactId> <version>1.0.4</version> </dependency>

Where [library-name] in both instances should be replaced by the desired client library name from the table above.

Usage

The Examples section of the User Guide has some self-contained usage examples. The following is a script which will extract the license information for Groovy from the Maven Repository site.

@Grab('io.github.http-builder-ng:http-builder-ng-core:1.0.4') @Grab('org.jsoup:jsoup:1.9.2') import static groovyx.net.http.HttpBuilder.configure import org.jsoup.nodes.Document Document page = configure { request.uri = 'https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all' }.get() String license = page.select('span.b.lic').collect { it.text() }.join(', ') println "Groovy is licensed under: ${license}"

which will print out:

Groovy is licensed under: Apache 2.0

when it is executed. The User Guide and JavaDocs have much more detailed information about usage and configuration.