https://github.com/codelibs/curl4j
curl-like Java Client
https://github.com/codelibs/curl4j
Last synced: 10 months ago
JSON representation
curl-like Java Client
- Host: GitHub
- URL: https://github.com/codelibs/curl4j
- Owner: codelibs
- License: apache-2.0
- Created: 2018-06-14T07:44:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-07-05T01:38:19.000Z (12 months ago)
- Last Synced: 2025-07-05T02:42:40.134Z (12 months ago)
- Language: Java
- Homepage:
- Size: 91.8 KB
- Stars: 2
- Watchers: 8
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
curl4j
[](https://github.com/codelibs/curl4j/actions/workflows/maven.yml)
=====
A simple cURL-like Java HTTP client.
## Features
- 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)
## Installation
### Maven
Add the dependency to your `pom.xml` (replace `x.y.z` with the latest version):
```xml
org.codelibs
curl4j
x.y.z
```
See [Maven Central](https://repo1.maven.org/maven2/org/codelibs/curl4j/) for available versions.
### Gradle
```groovy
implementation 'org.codelibs:curl4j:x.y.z'
```
## Quick Start
### Synchronous request
```java
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());
}
```
### Asynchronous request
```java
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());
```
## API Overview
- `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` and `ContentOutputStream`: internal utilities for streaming and caching.
Refer to the Javadoc for full API details.
## Building and Testing
```bash
git clone https://github.com/codelibs/curl4j.git
cd curl4j
mvn clean test
```
## License
This project is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.