Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-07T12:16:46.000Z (about 2 months ago)
- Last Synced: 2024-11-07T13:26:16.238Z (about 2 months ago)
- Topics: groovy, http, http-client
- Language: Java
- Homepage: https://github.com/tambapps/hyperpoet/wiki
- Size: 526 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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 isFor 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.HttpHaikuHttpPoet poet = new HttpPoet(url: API_URL)
def posts = poet.get("/posts", params: [author: '[email protected]'])
processPosts(posts)
// or if you don't want to instantiate a Poet
def todos = HttpHaiku.get("$API_URL/todos", [author: '[email protected]'])
```### Post data
```groovy
HttpPoet poet = new HttpPoet(url: API_URL, contentType: ContentType.JSON)
newPost = [title: 'a new post', author: '[email protected]', 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](https://github.com/tambapps/hyperpoet/blob/main/examples/example.png?raw=true)