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.ScalatraKernel.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!" }
Immediately halts the current action.
Immediately halts the current action. If called within a before filter, prevents the action from executing. Any matching after filters will still execute.
set as the response's HTTP status code. Ignored if null.
rendered to the response body through the response pipeline.
added as headers to the response. Previously set headers are retained
set as the HTTP status reason. Ignored if null or if status is null.
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
.
Immediately passes execution to the next matching route.
patch
get
get
The current request
The current response.
The current servlet context
Gets the content type of the current response.
Sets the content type of the current response.
Sends a redirect response and immediately halts the current action.
The current HTTP session.
The current HTTP session. Creates a session if none exists.
The current HTTP session.
The current HTTP session. If none exists, None is returned.
Sets the status code of the current response.
Use after() { ... }
Use after(RouteMatcher*) { ... }
Use before() { ... }
Use before(RouteMatcher*) { ... }
The core DSL of a Scalatra application.