Actions

We have talked about routes, and how to pass parameters to controllers. Let's now talk about what we can do with the controller.

The method defined in the route must return a play.api.mvc.Action instance. The Action type is a thin wrapper around the type Request[A] => Result, where Request[A] identifies an HTTP request and Result is an HTTP response.

Composing the response

An HTTP response, as we saw in Chapter 7, Web APIs, is composed of:

  • the status code (such as 200 for a successful response, or 404 for a missing page)
  • the response headers, a key-value list indicating metadata related to the response
  • The response body. This can be HTML for web pages, or JSON, XML or plain text (or many other formats). This is generally the bit that we are ...

Get Scala: Guide for Data Science Professionals now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.