Home

Awesome

Hyperpoet

Hyperpoet is a Marcel and Groovy-friendly HTTP client written in Java 8 backed by OkHttp.

The main goal of this library is to be able to perform HTTP requests with as less code as possible. It is

For that, several functionalities were implemented

You can also find features such as

Check out the full doc here

How to use

The library is in Maven central.

You can import it to your project with Maven

  <dependency>
    <groupId>com.tambapps.http</groupId>
    <artifactId>hyperpoet-groovy</artifactId>
    <version>1.4.0</version>
  </dependency>

Or Gradle

implementation 'com.tambapps.http:hyperpoet-groovy:1.4.0'

Or see this link for other dependency management tools.

Examples

Get an url

import com.tambapps.http.hyperpoet.HttpHaiku

HttpPoet poet = new HttpPoet(url: API_URL)
def posts = poet.get("/posts", params: [author: 'someone@gmail.com'])
processPosts(posts)
// or if you don't want to instantiate a Poet
def todos = HttpHaiku.get("$API_URL/todos", [author: 'someone@gmail.com'])

Post data

HttpPoet poet = new HttpPoet(url: API_URL, contentType: ContentType.JSON)
newPost = [title: 'a new post', author: 'me@gmail.com', body: 'This is new!']
try {
  poet.post("/posts", body: newPost)
} catch (ErrorResponseException e) {
  println "Couldn't create new post!"
}
// or if you don't want to instantiate a Poet
HttpHaiku.post("$API_URL/todos", contentType: ContentType.JSON, body: newPost)

Printing request/response data

Example