Skip to content

Commit

Permalink
Merge pull request #45 from Infomaniak/fix-post-request
Browse files Browse the repository at this point in the history
fix: Add post request Content-Type
  • Loading branch information
tevincent authored Oct 18, 2024
2 parents 03ed6ba + 3d73c53 commit 3ba47fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package com.infomaniak.multiplatform_swisstransfer.network.models.upload.response

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.InitUploadResponse
import kotlinx.serialization.Serializable

@Serializable
class InitUploadResponseApi : InitUploadResponse<UploadContainerApi> {
override var container: UploadContainerApi = UploadContainerApi()
override var uploadHost: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import io.ktor.client.HttpClient
import io.ktor.client.request.*
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.http.ContentType
import io.ktor.http.URLBuilder
import io.ktor.http.Url
import io.ktor.http.contentType
import kotlinx.serialization.json.Json

internal open class BaseRequest(protected val json: Json, protected val httpClient: HttpClient) {
Expand All @@ -40,11 +42,17 @@ internal open class BaseRequest(protected val json: Json, protected val httpClie
}

protected suspend inline fun <reified R> post(url: Url, data: Any?, httpClient: HttpClient = this.httpClient): R {
return httpClient.post(url) { setBody(data) }.decode<R>()
return httpClient.post(url) {
contentType(ContentType.Application.Json)
setBody(data)
}.decode<R>()
}

protected suspend inline fun <reified R> put(url: Url, data: Any?, httpClient: HttpClient = this.httpClient): R {
return httpClient.put(url) { setBody(data) }.decode<R>()
return httpClient.put(url) {
contentType(ContentType.Application.Json)
setBody(data)
}.decode<R>()
}

protected suspend inline fun <reified R> delete(url: Url, httpClient: HttpClient = this.httpClient): R {
Expand Down

0 comments on commit 3ba47fa

Please sign in to comment.