Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:18
Show Gist options
  • Select an option

  • Save dacr/f4383752bcd837136c38ee22d73a49ac to your computer and use it in GitHub Desktop.

Select an option

Save dacr/f4383752bcd837136c38ee22d73a49ac to your computer and use it in GitHub Desktop.
ZIO learning - zhttp - simplest https client / published by https://github.com/dacr/code-examples-manager #ce0d63a2-6791-4571-8950-373e06273894/1745c5c7e5c9dc6586ad27f3b0fd4768d110b225
// summary : ZIO learning - zhttp - simplest https client
// keywords : scala, zio, learning, pure-functional, zhttp, http-client, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : ce0d63a2-6791-4571-8950-373e06273894
// created-on : 2023-05-07T08:30:37+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "dev.zio::zio-http:3.0.0-RC1"
//> using dep "fr.janalyse::zio-worksheet:2.0.13.0"
// ---------------------
import zio.*, zio.worksheet.*, zio.http.*
import zio.http.netty.client.NettyClientDriver, zio.http.netty.NettyConfig
val url = "https://mapland.fr/lorem/api/paragraphs?minWordCount=10&maxWordCount=50"
val logic = for {
response <- Client.request(url)
content <- response.body.asString
_ <- Console.printLine(content)
} yield ()
val clientConfig = ZClient.Config.default.ssl(ClientSSLConfig.Default)
logic
.provide(
Client.customized,
DnsResolver.default,
NettyClientDriver.live,
ZLayer.succeed(clientConfig),
ZLayer.succeed(NettyConfig.default)
)
.unsafeRun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment