Skip to content

Repository files navigation

logo 2x

Introduction

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

Basic HTTP methods:

* GET
* POST
* PUT
* DELETE
* HEAD

Facilitating HTTP methods:

* POST with JSON payload
* PUT with JSON payload
* POST of type x-www-form-urlencoded

Decorators:

* Automatic retry in case of failure
* Automatic request caching with file storage or Redis
* Multi-host redirection
* AWS v4 authentication signing

Additional features:

* 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 requests

Installation

The 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

v4.8.0

master

17+

5.0.4

The application uses the current Groovy line.

v4.8.0-g4

groovy-4

17+

4.0.30

The application depends on Groovy 4.

v4.8.0-j8g3

java-8-groovy-3

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>

Usage example

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)
)

About

A series of decorators to add properties to your remote connection

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages