Requests and responses

Request

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

body
to get the request body as a string.
isAjax
to detect AJAX requests.
cookies
a Map view of the request's cookies.
multiCookies
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.

Response

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.

ServletContext

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