O'Reilly logo

RESTful Web Services with Scala by Jos Dirksen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing incoming requests using RequestReaders

So far, we haven't done anything yet with the incoming request. In the previous example, we just returned a string without using any information from the request. Finch provides a very nice model using a Reader monad, which you can use to easily combine information from an incoming request to instantiate new objects.

Note

A Reader monad is a standard functional design pattern, which allows you to define functions that all access the same values. A great explanation of how Reader monads work can be found at http://eed3si9n.com/learning-scalaz/Monad+transformers.html.

Let's look at some code that uses a RequestReader to process incoming requests (the complete source code can be found in the FinchStep2.scala ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required