-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #601 from Kevin-Lee/add-http4s-0.22-support
Add support for http4s `0.22.x` client generation - `httpclients_http4s_0_22.scala.template`
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
cli/src/main/resources/httpclients_http4s_0_22.scala.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package scalaxb | ||
|
||
import cats.effect._ | ||
import org.http4s._ | ||
import org.http4s.client._ | ||
import org.typelevel.ci._ | ||
|
||
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(CIString(name), 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) | ||
)(entityDecoder) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters