
com.github.kondaurovdev.http_client.JsonClient.scala Maven / Gradle / Ivy
The newest version!
package com.github.kondaurovdev.http_client
import com.github.kondaurovdev.http_client.models.HttpTimeouts
import play.api.libs.json.{Json, Writes}
import scalaj.http.{BaseHttp, HttpRequest}
case class JsonClient(timeouts: HttpTimeouts = HttpTimeouts()) extends BaseHttp(options = timeouts) {
def apply[T](url: String, data: T)(implicit writes: Writes[T]): HttpRequest = {
super.apply(url)
.headers(
"Content-Type" -> "application/json; charset=utf-8"
)
.postData(Json.toJson(data).toString().getBytes("UTF-8"))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy