avatar

Andres Jaimes

Creating an sbt project from scratch

Files and project structure

sbt projects use the same structure as Maven. Creating a project from scratch involve the following steps:

1mkdir some-new-project
2cd some-new-project
3mkdir -p src/{main,test}/{resources,scala}
4mkdir project

Create a …

Sending a message using telegram and scala

In this article we are going to use scala to send a message via Telegram. The process is very simple and pretty much involves setting up a bot and making a GET request to Telegram’s api.

The Telegram app on the phone has more features than its …

Testing scala classes and controllers

This article discusses different approaches for testing classes, services, and PlayFramework controllers using scalatest.

Setting up the project dependencies

First step is to add to build.sbt the next dependency:

1"org.scalatest" %% …

Enumerations

Using case object

Unlike other languages, Scala does not have a keyword for enumerations. One way to implement them is by using case objects. For example:

1sealed trait OperatingSystem extends Product with Serializable
2
3object OperatingSystem {
4 …

Akka Actors

The Play Framework is built upon Akka actors, but does everything so that you don’t really need to use them. Despite this, actors are easy to integrate with Play, precisely because it is built on them (there is already an actor system for you …

Check multiple option values in Scala

Two main approaches for doing this, the second one being for me the most appropriate.

Check values using regular if conditions:

1if (opt1.isDefined && opt2.isDefined && opt3.isDefined) // do something

Check values using match:

1(opt1, …

Creating and validating JWT JSON web tokens

This article goes through the process of creating and validating JWT’s (JSON web tokens) using Scala.

Our implementation uses the awesome io.jsonwebtoken library, and can be added to a sbt project like this:

1libraryDependencies ++= Seq( …