http-decò is a library designed to make executing HTTP requests in JDK languages as easy as possible. It provides a concise and intuitive API for basic HTTP methods and advanced features such as automatic retries, request caching, and AWS authentication.
Features
* POST with JSON payload
* PUT with JSON payload
* POST of type x-www-form-urlencoded* Automatic retry in case of failure
* Automatic request caching with file storage or Redis
* Multi-host redirection
* AWS v4 authentication signing* Support for basic authentication directly from URL userinfo
* Native support for http_proxy, https_proxy, no_proxy environment variables
* Easy disabling of HTTPS checks for testing with self-signed certificates
* Easy disabling of exceptions for failed requests
* Straightforward support for adding headers to requests
* Straightforward support for adding cookies to requestsThe http-decò library is available through JitPack. Groovy is an exported runtime dependency, so select the artifact matching the Groovy major used by your application.
| Version | Branch | Java | Groovy | Use it when |
|---|---|---|---|---|
|
|
17+ |
5.0.4 |
The application uses the current Groovy line. |
|
|
17+ |
4.0.30 |
The application depends on Groovy 4. |
|
|
8+ |
3.0.25 |
The application must remain compatible with Java 8 and Groovy 3. |
To start using it into your project, add the following dependency to your build.gradle file:
repositories {
maven { url = uri('https://jitpack.io') }
}
dependencies {
implementation 'com.github.grational:http-deco:v4.8.0'
}Or for your pom.xml file:
<dependency>
<groupId>com.github.grational</groupId>
<artifactId>http-deco</artifactId>
<version>v4.8.0</version>
</dependency>import it.grational.http.request.*
import it.grational.cache.*
import java.time.Duration
// Example of a GET request
def response = new Get("https://www.google.com").connect()
// Example of a POST request with JSON payload
def json = [name: "John Doe", age: 30]
response = new JsonPost (
url: "https://api.example.com/users",
map: [
name: 'John Doe',
age: 30
]
).connect()
// Usage example with automatic retry (3)
def response = new Retry (
new Get("https://www.polito.it")
)
// Usage example with file caching limited to 5 minutes
def response = new Cache (
new Get("https://www.polito.it"),
new CacheFile(),
Duration.ofMinutes(5)
)