Home

Awesome

If you don't have a working Scala development setup yet, please see the setup instructions

Exercise 1

In this exercise you will learn about a pattern known as the Receptionist.

The Receptionist has the following responsibilities:

Objective

The objective of this exercise is to get familiar with the Receptionist pattern. You will learn how a child actor is created by the Receptionist and how work is delegated to the child actor. Although Spray is used in the exercise it is not required to know Spray to complete the exercise, since all required code to hook up to HTTP is provided.

What is already prepared

A Main App which uses the Spray-can HTTP IO extension. This Main app creates the ActorSystem, starts the HTTP extension and registers the Receptionist Actor as HTTP listener. If you comment out the ReverseActorSpec the /reverse path should work. The Receptionist listens on the path "/reverse" for a HTTP POST of a JSON entity, for instance:

{ 
  "value" : "reverse this!"
}   

An example using the httpie command line tool:

  http POST localhost:8000/reverse value="reverse this\\!"

The result should be something like:

HTTP/1.1 200 OK
{
  "value": "!siht esrever"
}

In this exercise you will replace the default string reversal code inside the ReverseRoute (which is mixed into the Receptionist) with a call to a child actor: the ReverseActor.

The Exercise

Look for the TODO's in the project and follow the instructions. The following tasks will need to be completed:

Implement the ReverseActor (reverse a string and send back to sender).

The Receptionist receives a ReverseRequest which needs to be converted to the message that the ReverseActor understands.

Run the application

Next Exercise

A better way to create the child ReverseActor for easier unit testing of the Receptionist. Go to Exercise 2