How to Develop a Native macOS Command-Line Tool Using Scala 3
Briefly

The poke-http command-line tool is a Scala script designed to continuously check the availability of an HTTP service. By accepting a URL as a command-line argument, the script utilizes the sttp library to send HTTP GET requests until it receives a successful response. On success, it exits with "Success"; if unsuccessful, it prints a failure message, waits for three seconds, and retries. This approach streamlines monitoring HTTP services effectively.
//> using dep com.softwaremill.sttp.client3::core:3.10.3 import sttp.client3.quick.* import sttp.model.Uri val url = Uri.parse(args(0)).toOption.get def go(): Unit = { val getResult = simpleHttpClient.send(quickRequest.get(url)) if (getResult.code.isSuccess) { println("Success") } else { println("Failure, continue to try...") Thread.sleep(3000) go() } } go() This Scala script checks the availability of an HTTP service by continuously sending requests until it receives a successful response from the specified URL.
Poke-http continuously attempts to connect to a provided HTTP URL, echoing "Success" upon receiving a successful HTTP response, or "Failure, continue to try..." otherwise.
Once invoked with a specific URL, poke-http makes an initial request, then enters a sleep period followed by continued attempts until the service responds successfully.
Read at Medium
[
|
]