calaxb_2.12.1.12.1.source-code.httpclients_http4s_0_21.scala.template Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalaxb_2.12 Show documentation
Show all versions of scalaxb_2.12 Show documentation
scalaxb is an XML data-binding tool for Scala that supports W3C XML Schema (xsd) and wsdl.
The newest version!
package scalaxb
import cats.effect._
import org.http4s._
import org.http4s.implicits._
import org.http4s.client._
import scala.concurrent.duration._
trait Http4sClientsF[F[_]] extends HttpClientsF[F] { self =>
implicit protected def F: Concurrent[F]
protected def http4sClient: Client[F]
protected lazy val httpClient: Http4sClientF[F] = new Http4sClientF[F] {
implicit protected def F: Concurrent[F] = self.F
protected def http4sClient: Client[F] = self.http4sClient
}
trait Http4sClientF[G[_]] extends HttpClientF[G] {
implicit protected def F: Concurrent[G]
protected def http4sClient: Client[G]
protected def entityEncoder: EntityEncoder[G, String] =
EntityEncoder[G, String]
protected def entityDecoder: EntityDecoder[G, String] =
EntityDecoder[G, String]
override def request(
in: String,
address: java.net.URI,
headers: Map[String, String]
): G[String] =
request(
in = in,
uri = Uri.unsafeFromString(address.toString),
headers = Headers(headers.map { case (name, value) =>
Header.Raw(name.ci, value)
}.toList)
)
protected def request(in: String, uri: Uri, headers: Headers): G[String] = {
http4sClient
.expect[String](
Request[G](method = Method.POST, uri = uri)
.withEntity(in)(entityEncoder)
.putHeaders(headers.toList:_*)
)(entityDecoder)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy