Lightweight HTTP client DSL with retry, timeout, and JSON support
implementation com.philiprehberger:http-clientLightweight HTTP client DSL with retry, timeout, and JSON support.
implementation("com.philiprehberger:http-client:0.1.6")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>http-client</artifactId>
<version>0.1.6</version>
</dependency>
import com.philiprehberger.httpclient.*
val client = httpClient {
baseUrl = "https://api.example.com"
timeout = 10.seconds
defaultHeaders["Authorization"] = "Bearer $token"
}
val users = client.get("/users") { query("page", "1") }
val created = client.post("/users") { json(CreateUserRequest("Alice")) }
| Function / Class | Description |
|---|---|
httpClient { } | Create a configured HTTP client |
HttpClient.get(path) { } | GET request |
HttpClient.post(path) { json(body) } | POST with JSON body |
RequestBuilder.query(key, value) | Add query parameter |
RequestBuilder.header(name, value) | Add header |
RequestBuilder.form(vararg pairs) | Form-encoded body |
HttpResponse.json<T>() | Deserialize response body |
HttpResponse.isSuccess() | Check 2xx status |
HttpException | Thrown for non-2xx responses |
./gradlew test
./gradlew build
If you find this project useful: