avatar

Andres Jaimes

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.

A purely functional example using Scala

On this tutorial we’re going to explore the basics of purely functional programming using Scala. One of the principles with purely functional style, is that we have to define concepts in terms of functions. The basics: Comparing a number We’re going to create a simple function that lets us compare a number to a previously stored number in a purely functional way. For that, we can define the following function:

Examples of ‘for’ queries with Scala

On this page you are going to find some examples of ‘for’ queries. Let’s start by defining the following database: case class Book(title: String, authors: List[String]) val books: List[Book] = List( Book("structure and interpretation of computer programs", List("abelson, harald", "sussman, gerald j.")), Book("introduction to functional programming", List("bird, richard", "wadler, phil")), Book("effective java", List("bloch, joshua")), Book("java puzzlers", List("bloch, joshua", "gafter, neal")), Book("programming in scala", List("odersky, martin", "spoon, lex", "venners, bill")) ) Find the titles of books whose author’s name is ‘bird’