Skip to content

alexanderwolz/http-client

Repository files navigation

HTTP Client

GitHub release (latest by date) Maven Central Version GitHub GitHub code size in bytes GitHub all releases

🧑‍💻 About

This repository provide a sophisticated http client wrapper.

🛠️ Build

  1. Create jar resource using ./gradlew clean build
  2. Copy /build/libs/*.jar into your project
  3. Use the http client classes

📦 Getting the latest release

You can pull the latest binaries from the central Maven repositories:

with Gradle

implementation("de.alexanderwolz:http-client:1.4.4")

with Maven

<dependency>
  <groupId>de.alexanderwolz</groupId>
  <artifactId>http-client</artifactId>
    <version>1.4.4</version>
</dependency>

🪄 Example

val formPayload = Payload.create(
    BasicContentTypes.FORM_URL_ENCODED,
    Form(
        "grant_type" to "client_credentials",
        "client_id" to "XYZ12345",
        "client_secret" to "9876543ABC",
        "scope" to "oidc"
    )
)

val client = HttpClient.Builder()
    .method(HttpMethod.POST)
    .endpoint("https://sso.example.com/token")
    .accept(BasicContentTypes.OAUTH_TOKEN)
    .body(formPayload)
    .build()

val response = client.execute()
if (response.isOK && response.body.type == BasicContentTypes.OAUTH_TOKEN) {
    val accessToken = response.body.element as OAuthTokenResponse
} else{ 
    throw Exception("Received error ${response.code}")
}

Made with ❤️ in Bavaria
© 2025, Alexander Wolz

Sponsor this project

 

Packages

No packages published

Languages