package 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") } } }
- Source
- package.scala
- Alphabetic
- By Inheritance
- sird
- PathBindableExtractors
- RequestMethodExtractors
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- class OptionalQueryStringParameter extends QueryStringParameterExtractor[Option[String]]
- class PathBindableExtractor[T] extends AnyRef
An extractor that extracts from a String using a play.api.mvc.PathBindable.
- trait PathBindableExtractors extends AnyRef
Extractors that bind types from paths using play.api.mvc.PathBindable.
- class PathExtractor extends AnyRef
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
- type QueryString = Map[String, Seq[String]]
The query string type
- trait QueryStringParameterExtractor[T] extends AnyRef
- class RequestMethodExtractor extends AnyRef
An extractor that extracts requests by method.
- trait RequestMethodExtractors extends AnyRef
Extractors that extract requests by method.
- class RequiredQueryStringParameter extends QueryStringParameterExtractor[String]
- class SeqQueryStringParameter extends QueryStringParameterExtractor[Seq[String]]
- implicit class UrlContext extends AnyRef
Value Members
- val ?: &.type
Same as &, but for convenience to make the dsl look nicer when extracting query strings
- val DELETE: RequestMethodExtractor
Extracts a DELETE request.
Extracts a DELETE request.
- Definition Classes
- RequestMethodExtractors
- val GET: RequestMethodExtractor
Extracts a GET request.
Extracts a GET request.
- Definition Classes
- RequestMethodExtractors
- val HEAD: RequestMethodExtractor
Extracts a HEAD request.
Extracts a HEAD request.
- Definition Classes
- RequestMethodExtractors
- val OPTIONS: RequestMethodExtractor
Extracts an OPTIONS request.
Extracts an OPTIONS request.
- Definition Classes
- RequestMethodExtractors
- val PATCH: RequestMethodExtractor
Extracts a PATCH request.
Extracts a PATCH request.
- Definition Classes
- RequestMethodExtractors
- val POST: RequestMethodExtractor
Extracts a POST request.
Extracts a POST request.
- Definition Classes
- RequestMethodExtractors
- val PUT: RequestMethodExtractor
Extracts a PUT request.
Extracts a PUT request.
- Definition Classes
- RequestMethodExtractors
- val bool: PathBindableExtractor[Boolean]
A boolean extractor.
A boolean extractor.
- Definition Classes
- PathBindableExtractors
- val double: PathBindableExtractor[Double]
A double extractor.
A double extractor.
- Definition Classes
- PathBindableExtractors
- val float: PathBindableExtractor[Float]
A float extractor.
A float extractor.
- Definition Classes
- PathBindableExtractors
- val int: PathBindableExtractor[Int]
An int extractor.
An int extractor.
- Definition Classes
- PathBindableExtractors
- val long: PathBindableExtractor[Long]
A long extractor.
A long extractor.
- Definition Classes
- PathBindableExtractors
- object &
Allow multiple parameters to be extracted
- object PathExtractor
- object QueryStringParameterExtractor