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 org.scalatra.RouteMatcher and a block as the action body.
The Scalatra DSL core methods take a list of org.scalatra.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 org.scalatra.RouteMatcher, so you can write code naturally.
get("/", request.getRemoteHost == "127.0.0.1") { "Hello localhost!" }
head
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.
Defines a block to run if no matching routes are found, or if all matching routes pass.
get
patch
get
get
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.
Gets the content type of the current response.
Sets the content type of the current response.
Sets the content type of the current response.
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
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.
The current session.
The current session. Creates a session if none exists.
The current session.
The current session. If none exists, None is returned.
Gets the status code of the current response.
Gets the status code of the current response.
Sets the status code of the current response.
Sets the status code of the current response.
error
(Since version 2.1.0) Use status_=(Int) instead
The core Scalatra DSL.