Skip to content

Commit

Permalink
Add convenient request method to Client class (zio#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
palanga authored Aug 25, 2022
1 parent c1d2c57 commit 25ddd9c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions zio-http/src/main/scala/zhttp/service/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ import java.net.{InetSocketAddress, URI}
final case class Client[R](rtm: HttpRuntime[R], cf: JChannelFactory[JChannel], el: JEventLoopGroup)
extends HttpMessageCodec {

def request(
url: String,
method: Method = Method.GET,
headers: Headers = Headers.empty,
content: Body = Body.empty,
ssl: ClientSSLOptions = ClientSSLOptions.DefaultSSL,
): ZIO[EventLoopGroup with ChannelFactory, Throwable, Response] =
for {
uri <- ZIO.fromEither(URL.fromString(url))
res <- request(
Request(Version.Http_1_1, method, uri, headers, body = content),
clientConfig = Config(ssl = Some(ssl)),
)
} yield res

def request(request: Request, clientConfig: Config): Task[Response] =
for {
promise <- Promise.make[Throwable, Response]
Expand Down Expand Up @@ -162,11 +177,8 @@ object Client {
ssl: ClientSSLOptions = ClientSSLOptions.DefaultSSL,
): ZIO[EventLoopGroup with ChannelFactory, Throwable, Response] =
for {
uri <- ZIO.fromEither(URL.fromString(url))
res <- request(
Request(Version.Http_1_1, method, uri, headers, body = content),
clientConfig = Config(ssl = Some(ssl)),
)
clt <- make[Any]
res <- clt.request(url, method, headers, content, ssl)
} yield res

def request(
Expand Down

0 comments on commit 25ddd9c

Please sign in to comment.