Skip to content

Kotlin MultiPart BodyPublisher for the JDK HttpClient API.

License

Notifications You must be signed in to change notification settings

Foxcapades/lib-k-multipart

Repository files navigation

K-MultiPart

GitHub docs dokka violet Java 11 Maven Central

Kotlin multipart/form-data BodyPublisher implementation for the Java HttpClient API.

build.gradle.kts
  implementation("io.foxcapades.lib:k-multipart:1.2.1")

Usage

fun main(args: Array<String>) {
  val client = HttpClient.newHttpClient()

  val body = MultiPart.createBody {
    withPart {
      fieldName = "foo"
      withBody("bar")
    }

    withPart {
      fieldName = "fizz"
      withBody(File("buzz"))
    }
  }

  client.send(
    HttpRequest.newBuilder(URI(args[0]))
      .POST(body)
      .build(),
    HttpResponse.BodyHandlers.discarding()
  )
}

Releases

Version Docs Notes

v1.2.1

Dokka

  • Corrects issue with encoding of wide unicode characters.

  • Adds optional charset indicator for overall request body.

v1.2.0

Dokka

Adds new extension/mixin methods for the HttpRequest.Builder type allowing direct publishing of MultiPartBody instances.

v1.1.0

Dokka

Adds new methods to enable non-Kotlin JVM languages to use this library.

v1.0.1

Dokka

Fixes content-type detection for file body parts.

v1.0.0

Dokka

Initial release.