A simple cURL-like Java HTTP client.
- Fluent API for building HTTP requests (GET, POST, PUT, DELETE, HEAD, OPTIONS, CONNECT, TRACE)
- Support for query parameters, headers, body (String or stream), compression, SSL configuration, proxies, and timeouts
- Automatic in-memory or on-disk caching of request/response bodies
- Synchronous and asynchronous (callback) execution
- Minimal dependencies (only Apache Commons IO)
Add the dependency to your pom.xml
(replace x.y.z
with the latest version):
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>curl4j</artifactId>
<version>x.y.z</version>
</dependency>
See Maven Central for available versions.
implementation 'org.codelibs:curl4j:x.y.z'
import org.codelibs.curl.Curl;
import org.codelibs.curl.CurlResponse;
try (CurlResponse response = Curl.get("https://example.com")
.param("q", "curl4j")
.header("Accept", "application/json")
.executeSync()) {
System.out.println("Status: " + response.getHttpStatusCode());
System.out.println(response.getContentAsString());
}
import org.codelibs.curl.Curl;
Curl.post("https://api.example.com/items")
.body("{\"name\":\"item1\"}")
.header("Content-Type", "application/json")
.execute(
response -> System.out.println("Async status: " + response.getHttpStatusCode()),
error -> error.printStackTrace());
org.codelibs.curl.Curl
: entry point for HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, CONNECT, TRACE).org.codelibs.curl.CurlRequest
: builder for HTTP requests.org.codelibs.curl.CurlResponse
: wrapper for HTTP responses.org.codelibs.curl.CurlException
: unchecked exception for errors.org.codelibs.curl.io.ContentCache
andContentOutputStream
: internal utilities for streaming and caching.
Refer to the Javadoc for full API details.
git clone https://github.com/codelibs/curl4j.git
cd curl4j
mvn clean test
This project is licensed under the Apache License 2.0. See LICENSE for details.