play.api.routing.sird

The Play "String Interpolating Routing DSL", sird for short.

This provides:

  • Extractors for requests that extract requests by method, eg GET, POST etc.
  • A string interpolating path extractor
  • Extractors for binding parameters from paths to various types, eg int, long, double, bool.

The request method extractors return the original request for further extraction.

The path extractor supports three kinds of extracted values:

  • Path segment values. This is the default, eg p"/foo/$id". The value will be URI decoded, and may not traverse /'s.
  • Full path values. This can be indicated by post fixing the value with a *, eg p"/assets/$path*". The value will not be URI decoded, as that will make it impossible to distinguish between / and %2F.
  • Regex values. This can be indicated by post fixing the value with a regular expression enclosed in angle brackets. For example, p"/foo/$id<[0-9]+>. The value will not be URI decoded.

The extractors for primitive types are merely provided for convenience, for example, p"/foo/${int(id)}" will extract id as an integer. If id is not an integer, the match will simply fail.

Example usage:

import play.api.routing.sird._
import play.api.routing._
import play.api.mvc._

Router.from {
  case GET(p"/hello/$to") => Action {
    Results.Ok(s"Hello $to")
  }
  case PUT(p"/api/items/${int(id)}") => Action.async { req =>
    Items.save(id, req.body.json.as[Item]).map { _ =>
      Results.Ok(s"Saved item $id")
    }
  }
}

Attributes

Members list

Type members

Classlikes

object &

Allow multiple parameters to be extracted

Allow multiple parameters to be extracted

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
&.type

Attributes

Supertypes
class Object
trait Matchable
class Any
class PathBindableExtractor[T](implicit pb: PathBindable[T])

An extractor that extracts from a String using a play.api.mvc.PathBindable.

An extractor that extracts from a String using a play.api.mvc.PathBindable.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Extractors that bind types from paths using play.api.mvc.PathBindable.

Extractors that bind types from paths using play.api.mvc.PathBindable.

Attributes

Supertypes
class Object
trait Matchable
class Any
class PathExtractor(regex: Regex, partDescriptors: Seq[Value])

The path extractor.

The path extractor.

Supported data types that can be extracted from:

  • play.api.mvc.RequestHeader
  • String
  • java.net.URI
  • java.net.URL

Value parameters

partDescriptors

Descriptors saying whether each part should be decoded or not.

regex

The regex that is used to extract the raw parts.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object PathExtractor

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

An extractor that extracts requests by method.

An extractor that extracts requests by method.

Attributes

Supertypes
class Object
trait Matchable
class Any

Extractors that extract requests by method.

Extractors that extract requests by method.

Attributes

Supertypes
class Object
trait Matchable
class Any

Attributes

Supertypes
class Object
trait Matchable
class Any

Attributes

Supertypes
class Object
trait Matchable
class Any
implicit class UrlContext(sc: StringContext)

Attributes

Supertypes
class Object
trait Matchable
class Any

Types

The query string type

The query string type

Attributes

Value members

Concrete fields

val ?: &.type

Same as &, but for convenience to make the dsl look nicer when extracting query strings

Same as &, but for convenience to make the dsl look nicer when extracting query strings

Attributes

Inherited fields

Extracts a DELETE request.

Extracts a DELETE request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts a GET request.

Extracts a GET request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts a HEAD request.

Extracts a HEAD request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts an OPTIONS request.

Extracts an OPTIONS request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts a PATCH request.

Extracts a PATCH request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts a POST request.

Extracts a POST request.

Attributes

Inherited from:
RequestMethodExtractors

Extracts a PUT request.

Extracts a PUT request.

Attributes

Inherited from:
RequestMethodExtractors

A boolean extractor.

A boolean extractor.

Attributes

Inherited from:
PathBindableExtractors

A double extractor.

A double extractor.

Attributes

Inherited from:
PathBindableExtractors

A float extractor.

A float extractor.

Attributes

Inherited from:
PathBindableExtractors

An int extractor.

An int extractor.

Attributes

Inherited from:
PathBindableExtractors

A long extractor.

A long extractor.

Attributes

Inherited from:
PathBindableExtractors

A UUID extractor.

A UUID extractor.

Attributes

Inherited from:
PathBindableExtractors

Extensions

Extensions

extension (inline sc: StringContext)

String interpolator for required query parameters out of query strings.

String interpolator for required query parameters out of query strings.

The format must match q"paramName=${param}".

Attributes

String interpolator for multi valued query parameters out of query strings.

String interpolator for multi valued query parameters out of query strings.

The format must match q_*"paramName=${params}".

Attributes

String interpolator for optional query parameters out of query strings.

String interpolator for optional query parameters out of query strings.

The format must match q_?"paramName=${param}".

Attributes

String interpolator for optional query parameters out of query strings.

String interpolator for optional query parameters out of query strings.

The format must match q_o"paramName=${param}".

The q_? interpolator is preferred, however Scala 2.10 does not support operator characters in String interpolator methods.

Attributes

String interpolator for multi valued query parameters out of query strings.

String interpolator for multi valued query parameters out of query strings.

The format must match q_s"paramName=${params}".

The q_* interpolator is preferred, however Scala 2.10 does not support operator characters in String interpolator methods.

Attributes

Implicits

Implicits

final implicit def UrlContext(sc: StringContext): UrlContext