Last active
May 27, 2023 15:30
-
-
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/c1a7c588a291366c5fc520a35e24eff27aaefc1f
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
// summary : ZIO learning - zhttp - simplest https client | |
// keywords : scala, zio, learning, pure-functional, zhttp, http-client, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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.3.0" | |
//> 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