https://github.com/tambapps/hyperpoet
a Groovy-friendly and Marcel-friendly HTTP client backed by OkHttp
https://github.com/tambapps/hyperpoet
groovy http http-client
Last synced: 9 months ago
JSON representation
a Groovy-friendly and Marcel-friendly HTTP client backed by OkHttp
- Host: GitHub
- URL: https://github.com/tambapps/hyperpoet
- Owner: tambapps
- License: apache-2.0
- Created: 2021-04-08T21:20:00.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T17:54:26.000Z (11 months ago)
- Last Synced: 2025-04-08T14:12:06.002Z (10 months ago)
- Topics: groovy, http, http-client
- Language: Java
- Homepage: https://github.com/tambapps/hyperpoet/wiki
- Size: 542 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-groovy - Hyperpoet - Easy-to-use and customizable HTTP client for Groovy (HTTP)
README
# 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
- **Automatic I/O handling** :
No need to open and close Input/OutputStream, the poet does it for you
- **Automatic response body parsing** :
The poet automatically parse the response's data given its `Content-Type` header. You can also explicitly specify it yourself.
- **Automatic request body composing** :
The client/poet automatically compose the request's body (if any) given a provided content type.
You can also find features such as
- customize error handling
- handle authentication
- get history of requests/responses
- perform requests using Domain Specific Language
- printing request/responses (on a Linux terminal, useful with [groovysh](https://groovy-lang.org/groovysh.html))
Check out the full doc [here](https://github.com/tambapps/hyperpoet/wiki)
## How to use
The library is in Maven central.
You can import it to your project with Maven
```xml
com.tambapps.http
hyperpoet-groovy
1.4.0
```
Or Gradle
```groovy
implementation 'com.tambapps.http:hyperpoet-groovy:1.4.0'
```
Or see [this link](https://central.sonatype.com/artifact/com.tambapps.http/hyperpoet-groovy/1.4.0)
for other dependency management tools.
## Examples
### Get an url
```groovy
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
```groovy
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
