-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of reported remarks + adding example of command output…
… streaming with os-lib support.
- Loading branch information
1 parent
aaa1bd5
commit 8441264
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
examples/src/main/scala/sttp/client4/examples/cmdOutputStreamingWithOsLib.scala
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,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) | ||
} |