From 8441264aa73aa568cba3d3d1dd428a9b9493ac88 Mon Sep 17 00:00:00 2001 From: Adam Kaczmarek Date: Tue, 14 Jan 2025 11:30:06 +0100 Subject: [PATCH] Implementation of reported remarks + adding example of command output streaming with os-lib support. --- build.sbt | 3 ++- .../cmdOutputStreamingWithOsLib.scala | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 examples/src/main/scala/sttp/client4/examples/cmdOutputStreamingWithOsLib.scala diff --git a/build.sbt b/build.sbt index eee4fa940..c7cc19e6a 100644 --- a/build.sbt +++ b/build.sbt @@ -162,6 +162,7 @@ val zipkinSenderOkHttpVersion = "3.4.3" val resilience4jVersion = "2.3.0" val http4s_ce2_version = "0.22.15" val http4s_ce3_version = "0.23.30" +val osLibVersion = "0.11.3" val tethysVersion = "0.29.3" @@ -976,7 +977,7 @@ lazy val examples = (projectMatrix in file("examples")) "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % jsoniterVersion, "io.github.resilience4j" % "resilience4j-circuitbreaker" % resilience4jVersion, "io.github.resilience4j" % "resilience4j-ratelimiter" % resilience4jVersion, - "com.lihaoyi" %% "os-lib" % "0.11.3", + "com.lihaoyi" %% "os-lib" % osLibVersion, pekkoStreams, logback ), diff --git a/examples/src/main/scala/sttp/client4/examples/cmdOutputStreamingWithOsLib.scala b/examples/src/main/scala/sttp/client4/examples/cmdOutputStreamingWithOsLib.scala new file mode 100644 index 000000000..81f0b89c1 --- /dev/null +++ b/examples/src/main/scala/sttp/client4/examples/cmdOutputStreamingWithOsLib.scala @@ -0,0 +1,19 @@ +package sttp.client4.examples + +import sttp.client4.* +import os.* + +private val backend: SyncBackend = DefaultSyncBackend() +private val path: os.Path = os.Path("/tmp/example-file.txt") + +@main def cmdOutputStreamingWithOsLib(): Unit = { + os.remove(path) + os.write(path, "CONTENT OF THE SIMPLE FILE USED IN THIS EXAMPLE") + val process = os.proc("cat", path.toString).spawn() + val request = basicRequest + .post(uri"http://httpbin.org/post") + .body(process.stdout.wrapped) + .response(asString) + val response = request.send(backend) + println(response) +}