Requests and responses


Inside any action, the current request is available through the request variable. The underlying servlet request is implicitly extended with the following methods:

to get the request body as a string.
to detect AJAX requests.
a Map view of the request's cookies.
a Map view of the request's cookies.

The request also implements a scala.collection.mutable.Map backed by the request attributes.

The scalatra-http-demo is a good place to start if you need to see basic requests and response, cookies, and dealing with form input.


The response is available through the response variable.

If you override the Scalatra handling and write directly to the response object (e.g. response.getOutputStream), then your action should return Unit() to prevent a conflict with multiple writes.


The servlet context is available through the servletContext variable. The servlet context implicitly implements scala.collection.mutable.Map backed by servlet context attributes.