Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expression.
Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expression.
For example, to match www.sockoweb.com
, first define your regex as an object:
object MyHostRegex extends HostRegex("""www\.([a-z]+)\.com""".r)
Then, when defining your Route:
val r = Routes({ case MyHostRegex(m) => { assert(m.group(1) == "sockoweb") ... } })
Matches the "method" of HTTP org.mashupbots.socko.events.EndPoint
Matches the "method" of HTTP org.mashupbots.socko.events.EndPoint
You should not need to use this class. Rather use the objects that extends from this class. For example: org.mashupbots.socko.routes.GET.
Matches the path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expressions.
Matches the path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expressions.
For example, to match /path/to/file
, first define your regular expression as an object:
object MyPathRegex extends PathRegex("""/path/([a-z0-9]+)/([a-z0-9]+)""".r)
Then, when defining your Route:
val r = Routes({ case MyPathRegex(m) => { assert(m.group(1) == "to") assert(m.group(2) == "file") ... } })
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using field names.
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using field names.
If a match is found, the value is returned. If there are more than one value, on the first value is returned.
For example, to match ?name1=value1
, first define your match as an object:
object MyQueryStringField extends QueryStringName("name1")
Then, when defining your Route:
val r = Routes({ case MyQueryStringField(value) => { assert(value == "value1") ... } })
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expressions
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using regular expressions
For example, to match ?name1=value1
, first define your regular expression as an object:
object MyQueryStringRegex extends QueryStringRegex("""name1=([a-z0-9]+)""".r)
Then, when defining your Route:
val r = Routes({ case MyQueryStringRegex(m) => { assert(m.group(1) == "value1") ... } })
Concatenates 2 extractors in a case statement
Concatenates 2 extractors in a case statement
For example:
val r = Routes({ ctx @ GET(Path("/mypath")) & QueryString("name1=value1") => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to CONNECT
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to CONNECT
.
For example:
val r = Routes({ case CONNECT(ctx) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to DELETE
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to DELETE
.
For example:
val r = Routes({ case DELETE(ctx) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to GET
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to GET
.
For example:
val r = Routes({ case GET(ctx) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to HEAD
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to HEAD
.
For example:
val r = Routes({ case HEAD(ctx) => { ... } })
Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
For example, to match www.sockoweb.com
, use:
val r = Routes({ case Host("www.sockoweb.com") => { ... } })
This will match www.sockoweb.com
but not: www1.sockoweb.com
, sockoweb.com
or sockoweb.org
Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using segment patterns.
Matches the host of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using segment patterns.
For example, to match server1.sockoweb.com
, use:
val r = Routes({ case HostSegments(server :: "sockoweb" :: "com" :: Nil) => { // server will be set to server1 ... } })
Matches a Socko org.mashupbots.socko.events.HttpChunkEvent event.
Matches a Socko org.mashupbots.socko.events.HttpChunkEvent event.
For example:
val r = Routes({ case HttpChunk(httpChunk) => { ... } })
Matches a Socko org.mashupbots.socko.events.HttpRequestEvent.
Matches a Socko org.mashupbots.socko.events.HttpRequestEvent.
For example:
val r = Routes({ case HttpRequest(httpRequest) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to OPTIONS
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to OPTIONS
.
For example:
val r = Routes({ case OPTIONS(ctx) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to POST
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to POST
.
For example:
val r = Routes({ case POST(ctx) => { ... } })
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to PUT
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to PUT
.
For example:
val r = Routes({ case PUT(ctx) => { ... } })
Matches the case-sensitive path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
Matches the case-sensitive path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
For example, to match /folderX
use:
val r = Routes({ case Path("/folderX") => { ... } })
This will match /folderX
but not: /folderx
, /folderX/
or /TheFolderX
Matches the path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using segment patterns.
Matches the path of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents using segment patterns.
For example, to match /record/1
, use:
val r = Routes({ case PathSegments("record" :: id :: Nil) => { // id will be set to 1 ... } })
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
Matches the query string of org.mashupbots.socko.events.EndPoints in org.mashupbots.socko.events.SockoEvents.
For example, to match http://www.sockoweb.org/do?action=save
:
val r = Routes({ case QueryString("action=save") => { ... } })
Routes define the rules for dispatching events to its intended Akka handlers.
Routes define the rules for dispatching events to its intended Akka handlers. It is implemented as a list of PartialFunctions.
To assist with routing, Socko has the following extractors:
Example of a single list of partial functions:
val r = Routes({ case GET(PathSegments("record" :: id :: Nil)) => { ... } case PathSegments("record" :: id :: Nil) => { ... } })
Example of 2 lists of partial functions:
val r = Routes( { case GET(PathSegments("record" :: id :: Nil)) => { ... } case PathSegments("record" :: id :: Nil) => { ... } }, { case PUT(Host("aaa.abc.com")) & Path("/test1") => { ... } case Host("aaa.abc.com") & Path("/test2") => { ... } })
This area of code uses extractors, also known as the unapply
method. It is important to understand
how to use these patterns.
event @
is scala's variable binding pattern. It will be assigned the value of the matching SockoEventGET(x)
and Path(y)
are extractors. In the case of GET,
x is the same SockoEvent as
event. For
Path,
y is the path as a string. In other words, the value in between the parentheses is the return value of the
associated
unapply method.
&
chains together extractors like a logical AND
This article
explains how chaining of PartialFunction
works using orElse
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to TRACE
.
Matches org.mashupbots.socko.events.EndPoints of org.mashupbots.socko.events.SockoEvents
where the method is set to TRACE
.
For example:
val r = Routes({ case TRACE(ctx) => { ... } })
Matches a Socko org.mashupbots.socko.events.WebSocketFrameEvent event.
Matches a Socko org.mashupbots.socko.events.WebSocketFrameEvent event.
For example:
val r = Routes({ case WebSocketFrame(wsFrame) => { ... } })
Matches a Socko org.mashupbots.socko.events.WebSocketHandshakeEvent event.
Matches a Socko org.mashupbots.socko.events.WebSocketHandshakeEvent event.
For example:
val r = Routes({ case WebSocketHandshake(wsHandshake) => { ... } })
Routes define the rules for dispatching requests to its intended Akka actor handlers.