Adds a filter to run after the route.
Adds a filter to run after the route. The filter only runs if each routeMatcher returns Some. If the routeMatchers list is empty, the filter runs for all routes.
Adds a filter to run before the route.
Adds a filter to run before the route. The filter only runs if each routeMatcher returns Some. If the routeMatchers list is empty, the filter runs for all routes.
get
Defines an error handler for exceptions thrown in either the before block or a route action.
Defines an error handler for exceptions thrown in either the before block or a route action.
If the error handler does not match, the result falls through to the previously defined error handler. The default error handler simply rethrows the exception.
The error handler is run before the after filters, and the result is rendered like a standard response. It is the error handler's responsibility to set any appropriate status code.
The Scalatra DSL core methods take a list of RouteMatcher and a block as the action body.
The Scalatra DSL core methods take a list of RouteMatcher and a block as the action body. The return value of the block is rendered through the pipeline and sent to the client as the response body.
See org.scalatra.ScalatraBase#renderResponseBody for the detailed behaviour and how to handle your response body more explicitly, and see how different return types are handled.
The block is executed in the context of a CoreDsl instance, so all the methods defined in this trait are also available inside the block.
get("/") { <form action="/echo"> <label>Enter your name</label> <input type="text" name="name"/> </form> } post("/echo") { "hello {params('name)}!" }
ScalatraKernel provides implicit transformation from boolean blocks, strings and regular expressions to RouteMatcher, so you can write code naturally.
get("/", request.getRemoteHost == "127.0.0.1") { "Hello localhost!" }
Handles a request and writes to the response.
Handles a request and writes to the response.
Defines a block to run if matching routes are found only for other methods.
Defines a block to run if matching routes are found only for other methods. The set of matching methods is passed to the block.
A multi-map of the current parameters.
A multi-map of the current parameters. Parameters may come from: - the query string - the POST body - the route matchers of the currently executing route
The map has a default value of Seq.empty
.
Defines a block to run if no matching routes are found, or if all matching routes pass.
get
A map of the current parameters.
A map of the current parameters. The map contains the head of every
non-empty value in multiParams
.
patch
get
get
The current request
The current response.
Error handler for HTTP response status code range.
Error handler for HTTP response status code range. You can intercept every response code previously specified with #status or even generic 404 error.
trap(403) { "You are not authorized" } }*
}}
Gets the content type of the current response.
Sets the content type of the current response.
Immediately halts processing of a request.
Immediately halts processing of a request. Can be called from either a before filter or a route.
the status to set on the response, or null to leave the status unchanged.
a result to render through the render pipeline as the body
headers to add to the response
the HTTP status reason to set, or null to leave unchanged.
Immediately exits from the current route.
Immediately exits from the current route.
Sends a redirect response and immediately halts the current action.
Gets the status code of the current response.
Sets the status code of the current response.
error
The core Scalatra DSL.