Try use Ammonite Scala REPL

Gilmar Soares
2 min readJun 18, 2021

--

Lately I have been using Scala in my work, and I decided to write about a tool that has been helping me to test Scala and libraries. Ammonite.
Ammonite it’s a Scala REPL, but have any differences.
To install Ammonite you’ll use this link with your guide.

Next step after installation, is try use and this article help you in first steps.

I could show to you the basic commands like plus two number or println but I’ll show like you can make a requests to a API without create a Scala project to test the library for example.
The first command that you can test this is: “import

$ivy.`com.lihaoyi:requests_2.12:0.6.9`”

This command will install requests library and you can use in your Scala REPL.

Next step after install requests library is try use.
I’ll use “httpstat” to try requests with GET and POST.

Use the command:

val response = requests.get(“https://httpstat.us/200")

This command execute request GET to API and salve result in “variable” response.

The result is:
@ val response = requests.get(“https://httpstat.us/200")
response: requests.Response = Response(
https://httpstat.us/200",
200,
“OK”,
200 OK,
HashMap(
“cache-control” -> List(“private”),
“request-context” -> List(“appId=cid-v1:7585021b-2db7–4da6-abff-2cf23005f0a9”),
“expect-ct” -> List(“max-age=604800, report-uri=\”https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""),
“x-aspnetmvc-version” -> List(“5.1”),
“date” -> List(“Fri, 18 Jun 2021 11:26:20 GMT”),
“content-type” -> List(“text/plain; charset=utf-8”),
“set-cookie” -> List(“ARRAffinity=77a741f9a071462c94c5b3927f74f614213d2c9d14e54a7d5ce1e7123f6b018c;Path=/;HttpOnly;Domain=httpstat.us”),
“connection” -> List(“keep-alive”),
“x-aspnet-version” -> List(“4.0.30319”),
“vary” -> List(“Accept-Encoding”),
“content-encoding” -> List(“gzip”),
“cf-cache-status” -> List(“DYNAMIC”),
“server” -> List(“cloudflare”),
“access-control-allow-origin” -> List(“*”),
“cf-request-id” -> List(“0ac07844030000f5eb4aa4f000000001”),
“cf-ray” -> List(“661429800d02f5eb-GRU”),
“nel” -> List(“{\”report_to\”:\”cf-nel\”,\”max_age\”:604800}”),
“content-length” -> List(“126”),
“access-control-expose-headers” -> List(“Request-Context”, “Link, Content-Range, Location, WWW-Authenticate, Proxy-Authenticate, Retry-After”),

This is a small example to use Ammonite Scala REPL, I’ll try others examples, but that’s it for now.

--

--