trait Router extends AnyRef
Used for routing request handlers.
import scamper.Implicits.stringToEntity import scamper.ResponseStatus.Registry.{ NotFound, Ok } import scamper.server.HttpServer import scamper.server.Implicits.ServerHttpRequestType val app = HttpServer.app() // Mount router to /api app.route("/api") { router => val messages = Map(1 -> "Hello, world!", 2 -> "Goodbye, cruel world!") // Map handler to /api/messages router.get("/messages") { req => Ok(messages.mkString("\r\n")) } // Map handler to /api/messages/:id router.get("/messages/:id") { req => val id = req.params.getInt("id") messages.get(id) .map(Ok(_)) .getOrElse(NotFound()) } }
- See also
- Alphabetic
- By Inheritance
- Router
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
incoming(path: String, methods: RequestMethod*)(handler: RequestHandler): Router.this.type
Adds supplied handler for requests with given router path and any of specified request methods.
Adds supplied handler for requests with given router path and any of specified request methods.
The handler is appended to existing request handler chain.
- path
router path
- methods
request methods
- handler
request handler
- returns
this router
- Note
If no request methods are specified, then matches are limited to path only.
-
abstract
def
incoming(handler: RequestHandler): Router.this.type
Adds supplied request handler.
Adds supplied request handler.
The handler is appended to existing request handler chain.
- handler
request handler
- returns
this router
-
abstract
def
mountPath: String
Gets mount path.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
delete(path: String)(handler: RequestHandler): Router.this.type
Adds supplied handler for DELETE requests to given router path.
Adds supplied handler for DELETE requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
files(path: String, source: File): Router.this.type
Mounts file server at given path.
Mounts file server at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a file in the source directory or one of its subdirectories.
File Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
/tmp
/images/logo.png
/tmp/logo.png
/images
/tmp
/images/icons/warning.png
/tmp/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which files are served
- returns
this router
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
get(path: String)(handler: RequestHandler): Router.this.type
Adds supplied handler for GET requests to given router path.
Adds supplied handler for GET requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
post(path: String)(handler: RequestHandler): Router.this.type
Adds supplied handler for POST requests to given router path.
Adds supplied handler for POST requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
-
def
put(path: String)(handler: RequestHandler): Router.this.type
Adds supplied handler for PUT requests to given router path.
Adds supplied handler for PUT requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
-
def
resources(path: String, source: String, loader: ClassLoader): Router.this.type
Mounts file server (for resources) at given path.
Mounts file server (for resources) at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a resource in the source directory or one of its subdirectories.
Resource Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
assets
/images/logo.png
assets/logo.png
/images
assets
/images/icons/warning.png
assets/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which resources are served
- loader
class loader with which resources are loaded
- returns
this router
-
def
resources(path: String, source: String): Router.this.type
Mounts file server (for resources) at given path.
Mounts file server (for resources) at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a resource in the source directory or one of its subdirectories.
Resource Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
assets
/images/logo.png
assets/logo.png
/images
assets
/images/icons/warning.png
assets/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which resources are served
- returns
this router
- Note
The current thread's context class loader is used to load resources.
-
def
route[T](path: String)(routing: (Router) ⇒ T): Router.this.type
Adds new router at given path.
Adds new router at given path.
A new router is created and passed to routing application.
- path
router path at which new router is mounted
- routing
routing application
- returns
this router
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toAbsolutePath(path: String): String
Expands supplied router path to its absolute path.
Expands supplied router path to its absolute path.
- path
router path
- Exceptions thrown
IllegalArgumentException
if router path is not*
and does not begin with/
or if it escapes mount path- Note
If
*
is supplied as router path, its absolute path is also*
.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
websocket[T](path: String)(handler: (WebSocketSession) ⇒ T): Router.this.type
Adds WebSocket server at given router path using supplied session handler for each connection.
Adds WebSocket server at given router path using supplied session handler for each connection.
The handler is appended to existing request handler chain.
- path
WebSocket path
- handler
WebSocket session handler
- returns
this router
Provided herein is API documentation for Scamper, the HTTP library for Scala.