rybalkinsd / kohttp

Kotlin DSL http client
https://kohttp.gitbook.io
Apache License 2.0
478 stars 42 forks source link

Simplify multipart body requests #126

Closed rybalkinsd closed 5 years ago

rybalkinsd commented 5 years ago

At the moment multipart requests look like this:

  val token = ...
  val yourFile = ...

  val response = httpPost {
      url("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart")
      header {
          "Authorization" to "Bearer $token"
      }

      multipartBody {
          +FormDataPart("meta", null, RequestBody.create(
                  MediaType.get("application/json"),
                  json {
                     "name" to "supercat" 
                  }
          ))
          +form("image", yourFile)
      }
  }

FormDataPart primitive is not user-friendly. Would be nice to have an easy one-liner for part of multipart body. Would be nice to produce a body { } part the same way as in mono-body request.

Also good to check uploadType=resumable from Google Drive API v3

See #125

rybalkinsd commented 5 years ago

https://github.com/rybalkinsd/kohttp/pull/148