CARVIEW |
Introduction
What is the Scala Toolkit?
The Scala Toolkit is a set of libraries designed to effectively perform common programming tasks. It includes tools for working with files and processes, parsing JSON, sending HTTP requests, and unit testing.
The Toolkit supports:
- Scala 3 and Scala 2
- JVM, Scala.js, and Scala Native
Use cases for the Toolkit include:
- short-lived programs running on the JVM, to scrape a website, to collect and transform data, or to fetch and process some files,
- frontend scripts that run on the browser and power your websites,
- command-line tools packaged as native binaries for instant startup
Tests
Testing code with MUnit.
Files and Processes
Writing files and running processes with OS-Lib.
JSON
Parsing JSON and serializing objects to JSON with uPickle.
HTTP Requests
Sending HTTP requests and uploading files with sttp.
Web servers
Building web servers with Cask.
What are these tutorials?
This series of tutorials focuses on short code examples, to help you get started quickly.
If you need more in-depth information, the tutorials include links to further documentation for all of the libraries in the toolkit.
How to run the code?
You can follow the tutorials regardless of how you choose to run your Scala code. The tutorials focus on the code itself, not on the process of running it.
Ways to run Scala code include:
- in your browser with Scastie
- pros: zero installation, online sharing
- cons: single-file only, online-only
- interactively in the Scala REPL (Read/Eval/Print Loop)
- pros: interactive exploration in the terminal
- cons: doesn’t save your code anywhere
- interactively in a worksheet in your IDE such as IntelliJ or Metals
- pros: interactive exploration in a GUI
- cons: requires worksheet environment to run
- in scripts, using Scala CLI
- pros: terminal-based workflow with little setup
- cons: may not be suitable for large projects
- using a build tool (such as sbt or mill)
- pros: terminal-based workflow for projects of any size
- cons: requires some additional setup and learning
- using an IDE such as IntelliJ or Metals
- pros: GUI based workflow for projects of any size
- cons: requires some additional setup and learning
These choices, with their pros and cons, are common to most programing languages. Feel free to use whichever option you’re most comfortable with.
Contributors to this page:
Contents
- Introduction
- Testing with MUnit
- How to write tests?
- How to run tests?
- How to run a single test?
- How to test exceptions?
- How to write asynchronous tests?
- How to manage the resources of a test?
- What else can MUnit do?
- Working with files and processes with OS-Lib
- How to read a directory?
- How to read a file?
- How to write a file?
- How to run a process?
- What else can OS-Lib do?
- Handling JSON with uPickle
- How to access values inside JSON?
- How to modify JSON?
- How to deserialize JSON to an object?
- How to serialize an object to JSON?
- How to read and write JSON files?
- What else can uPickle do?
- Sending HTTP requests with sttp
- How to send a request?
- How to construct URIs and query parameters?
- How to send a request with a body?
- How to send and receive JSON?
- How to upload a file over HTTP?
- What else can sttp do?
- Building web servers with Cask
- How to serve a static file?
- How to serve a dynamic page?
- How to handle query parameters?
- How to handle user input?
- How to use websockets?
- How to use cookies and decorators?