org.mashupbots.socko

routes

package routes

Routes define the rules for dispatching requests to its intended Akka actor handlers.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. routes
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class HostRegex extends AnyRef

    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")
        ...
      }
    })
  2. class Method extends AnyRef

    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.

  3. class PathRegex extends AnyRef

    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")
        ...
      }
    })
  4. class QueryStringField extends AnyRef

    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")
        ...
      }
    })
  5. class QueryStringRegex extends AnyRef

    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")
        ...
      }
    })

Value Members

  1. object &

    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") => {
        ...
      }
    })
  2. object CONNECT extends Method

    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) => {
        ...
      }
    })
  3. object DELETE extends Method

    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) => {
        ...
      }
    })
  4. object GET extends Method

    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) => {
        ...
      }
    })
  5. object HEAD extends Method

    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) => {
        ...
      }
    })
  6. object Host

    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

  7. object HostSegments

    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
        ...
      }
    })
  8. object HttpChunk

    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) => {
        ...
      }
    })
  9. object HttpRequest

    Matches a Socko org.mashupbots.socko.events.HttpRequestEvent.

    Matches a Socko org.mashupbots.socko.events.HttpRequestEvent.

    For example:

    val r = Routes({
      case HttpRequest(httpRequest) => {
        ...
      }
    })
  10. object OPTIONS extends Method

    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) => {
        ...
      }
    })
  11. object POST extends Method

    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) => {
        ...
      }
    })
  12. object PUT extends Method

    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) => {
        ...
      }
    })
  13. object Path

    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

  14. object PathSegments

    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
        ...
      }
    })
  15. object QueryString

    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") => {
        ...
      }
    })
  16. object Routes

    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:

    • HTTP Method: GET, POST, PUT, DELETE, HEAD, CONNECT, OPTIONS, TRACE
    • HTTP Path: Path, PathSegments, PathRegex
    • HTTP Host: Host, HostSegments, HostRegex
    • HTTP Query String: QueryString, QueryStringRegex

    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 SockoEvent
    • GET(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.

  17. object TRACE extends Method

    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) => {
        ...
      }
    })
  18. object WebSocketFrame

    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) => {
        ...
      }
    })
  19. object WebSocketHandshake

    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) => {
        ...
      }
    })

Inherited from AnyRef

Inherited from Any

Ungrouped