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: if (opt1.isDefined && opt2.isDefined && opt3.isDefined) // do something Check values using match: (opt1, opt2, opt3) match { case(Some(val1), Some(val2), Some(val3)) => ??? case _ => ??? }

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: libraryDependencies ++= Seq("io.jsonwebtoken" % "jjwt" % "0.9.1") Creating a token We are going to use Scala’s apply/unapply functions for this implementation. This will allow us to use matchers for checking JWT’s. import java.time.Instant import java.util.{Date, UUID} import io.

Make a request to a remote service

This article shows how to make remote requests to services using Scala and the Play-Framework. It documents some recommended features that can improve the reliability of the request. Setup Make sure you add the following dependency to build.sbt libraryDependencies += ws GET request GET request to a remote service import scala.concurrent.Future import play.api.http.Status._ import play.api.libs.ws.WSClient import play.api.libs.json.{JsSuccess, Json} case class UnexpectedResponseStatus(message: String) extends Exception(message) case class InvalidServiceResponse(message: String) extends Exception(message) class SomeClass @Inject()( ws: WSClient ) { def getFromRemoteService(url: String): Future[Option[MyClass]] = { ws.