play.api.routing

sird

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
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. sird
  2. PathBindableExtractors
  3. RequestMethodExtractors
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class PathBindableExtractor[T] extends AnyRef

    An extractor that extracts from a String using a PathBindable.

  2. trait PathBindableExtractors extends AnyRef

    Extractors that bind types from paths using PathBindable.

  3. implicit class PathContext extends AnyRef

    String interpolator for extracting parameters out of URL paths.

    String interpolator for extracting parameters out of URL paths.

    By default, any sub value extracted out by the interpolator will match a path segment, that is, any String not containing a /, and its value will be decoded. If however the sub value is suffixed with *, then it will match any part of a path, and not be decoded. Regular expressions are also supported, by suffixing the sub value with a regular expression in angled brackets, and these are not decoded.

  4. 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
  5. class RequestMethodExtractor extends AnyRef

    An extractor that extracts requests by method.

  6. trait RequestMethodExtractors extends AnyRef

    Extractors that extract requests by method.

Value Members

  1. val DELETE: RequestMethodExtractor

    Extracts a DELETE request.

    Extracts a DELETE request.

    Definition Classes
    RequestMethodExtractors
  2. val GET: RequestMethodExtractor

    Extracts a GET request.

    Extracts a GET request.

    Definition Classes
    RequestMethodExtractors
  3. val HEAD: RequestMethodExtractor

    Extracts a HEAD request.

    Extracts a HEAD request.

    Definition Classes
    RequestMethodExtractors
  4. val OPTIONS: RequestMethodExtractor

    Extracts an OPTIONS request.

    Extracts an OPTIONS request.

    Definition Classes
    RequestMethodExtractors
  5. val PATCH: RequestMethodExtractor

    Extracts a PATCH request.

    Extracts a PATCH request.

    Definition Classes
    RequestMethodExtractors
  6. val POST: RequestMethodExtractor

    Extracts a POST request.

    Extracts a POST request.

    Definition Classes
    RequestMethodExtractors
  7. val PUT: RequestMethodExtractor

    Extracts a PUT request.

    Extracts a PUT request.

    Definition Classes
    RequestMethodExtractors
  8. object PathExtractor

  9. val bool: PathBindableExtractor[Boolean]

    A boolean extractor.

    A boolean extractor.

    Definition Classes
    PathBindableExtractors
  10. val double: PathBindableExtractor[Double]

    A double extractor.

    A double extractor.

    Definition Classes
    PathBindableExtractors
  11. val float: PathBindableExtractor[Float]

    A float extractor.

    A float extractor.

    Definition Classes
    PathBindableExtractors
  12. val int: PathBindableExtractor[Int]

    An int extractor.

    An int extractor.

    Definition Classes
    PathBindableExtractors
  13. val long: PathBindableExtractor[Long]

    A long extractor.

    A long extractor.

    Definition Classes
    PathBindableExtractors

Inherited from PathBindableExtractors

Inherited from RequestMethodExtractors

Inherited from AnyRef

Inherited from Any

Ungrouped