org.scalatra

CoreDsl

trait CoreDsl extends Handler with Control

The core Scalatra DSL.

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. CoreDsl
  2. Control
  3. Handler
  4. ServletApiImplicits
  5. AnyRef
  6. Any
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def after(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Unit

    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.

  2. abstract def before(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Unit

    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.

  3. abstract def delete(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    See also

    get

  4. abstract def error(handler: ErrorHandler): Unit

    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.

  5. abstract def get(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    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!" }
    
  6. abstract def handle(request: HttpServletRequest, res: HttpServletResponse): Unit

    Handles a request and writes to the response.

    Handles a request and writes to the response.

    Definition Classes
    Handler
  7. abstract def methodNotAllowed(block: (Set[HttpMethod]) ⇒ Any): Unit

    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.

  8. abstract def multiParams: MultiParams

    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.

  9. abstract def notFound(block: ⇒ Any): Unit

    Defines a block to run if no matching routes are found, or if all matching routes pass.

  10. abstract def options(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    See also

    get

  11. abstract def params: Map[String, String]

    A map of the current parameters.

    A map of the current parameters. The map contains the head of every non-empty value in multiParams.

  12. abstract def patch(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    See also

    patch

  13. abstract def post(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    See also

    get

  14. abstract def put(transformers: (Route) ⇒ Route*)(block: ⇒ Any): Route

    See also

    get

  15. implicit abstract def request: HttpServletRequest

    The current request

  16. implicit abstract def response: HttpServletResponse

    The current response.

  17. implicit abstract def servletContext: ServletContext

  18. abstract def trap(codes: Range)(block: ⇒ Any): Unit

    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"
      }
       }* 
    

    }}

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. def contentType: String

    Gets the content type of the current response.

  9. def contentType_=(contentType: String): Unit

    Sets the content type of the current response.

  10. implicit def enrichRequest(request: HttpServletRequest): RichRequest

    Definition Classes
    ServletApiImplicits
  11. implicit def enrichResponse(response: HttpServletResponse): RichResponse

    Definition Classes
    ServletApiImplicits
  12. implicit def enrichServletContext(servletContext: ServletContext): RichServletContext

    Definition Classes
    ServletApiImplicits
  13. implicit def enrichSession(session: HttpSession): RichSession

    Definition Classes
    ServletApiImplicits
  14. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  17. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  18. def halt(result: ActionResult): Nothing

    Definition Classes
    Control
  19. def halt[T](status: Integer, body: T, headers: Map[String, String], reason: String)(implicit arg0: Manifest[T]): Nothing

    Immediately halts processing of a request.

    Immediately halts processing of a request. Can be called from either a before filter or a route.

    status

    the status to set on the response, or null to leave the status unchanged.

    body

    a result to render through the render pipeline as the body

    headers

    headers to add to the response

    reason

    the HTTP status reason to set, or null to leave unchanged.

    Definition Classes
    Control
  20. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  25. def pass(): Nothing

    Immediately exits from the current route.

    Immediately exits from the current route.

    Definition Classes
    Control
  26. def redirect(uri: String): Unit

    Sends a redirect response and immediately halts the current action.

  27. def status: Int

    Gets the status code of the current response.

  28. def status_=(code: Int): Unit

    Sets the status code of the current response.

  29. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  30. def toString(): String

    Definition Classes
    AnyRef → Any
  31. def trap(code: Int)(block: ⇒ Any): Unit

    See also

    error

  32. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  33. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  34. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Deprecated Value Members

  1. def applicationContext: ServletContext

    Annotations
    @deprecated
    Deprecated

    (Since version 2.1.0) Use servletContext instead

  2. def status(code: Int): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 2.1.0) Use status_=(Int) instead

Inherited from Control

Inherited from Handler

Inherited from ServletApiImplicits

Inherited from AnyRef

Inherited from Any