Package

io.finch

request

Permalink

package request

This package introduces types and functions that enable _request processing_ in Finch. The io.finch.request primitives allow both to _read_ the various request items (query string param, header and cookie) using the RequestReader and _validate_ them using the ValidationRule.

The cornerstone abstraction of this package is a RequestReader, which is responsible for reading any amount of data from the HTTP request. RequestReaders might be composed with each other using either monadic API (flatMap method) or applicative API (:: method). Regardless the API used for RequestReaders composition, the main idea behind it is to use primitive readers (i.e., param, paramOption) in order to _compose_ them together and _map_ to the application domain data.

case class Complex(r: Double, i: Double)
val complex: RequestReader[Complex] = (
  param("real").as[Double] ::
  paramOption("imaginary").as[Double].withDefault(0.0)
).as[Complex]

A ValidationRule enables a reusable way of defining a validation rules in the application domain. It might be composed with RequestReaders using either should or shouldNot methods and with other ValidationRules using logical methods and and or.

case class User(name: String, age: Int)
val user: RequestReader[User] = (
  param("name").should(beLongerThan(3)) ::
  param("age").as[Int].should(beGreaterThan(0) and beLessThan(120))
).as[User]
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. request
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. trait DecodeAnyRequest extends AnyRef

    Permalink

    An abstraction that is responsible for decoding the request of general type.

  2. trait DecodeRequest[A] extends AnyRef

    Permalink

    An abstraction that is responsible for decoding the request of type A.

  3. type FileUpload = org.jboss.netty.handler.codec.http.multipart.FileUpload

    Permalink

    A type alias for a org.jboss.netty.handler.codec.http.multipart.FileUpload to prevent imports.

  4. case class NotParsed(item: RequestItem, targetType: ClassTag[_], cause: Throwable) extends RequestError with Product with Serializable

    Permalink

    An exception that indicates that a request item could be parsed.

    An exception that indicates that a request item could be parsed.

    item

    the invalid request item

    targetType

    the type the item should be converted into

    cause

    the cause of the parsing error

  5. case class NotPresent(item: RequestItem) extends RequestError with Product with Serializable

    Permalink

    An exception that indicates a required request item (header, param, cookie, body) was missing in the request.

    An exception that indicates a required request item (header, param, cookie, body) was missing in the request.

    item

    the missing request item

  6. case class NotValid(item: RequestItem, rule: String) extends RequestError with Product with Serializable

    Permalink

    An exception that indicates a broken ValidationRule]] on the request item.

    An exception that indicates a broken ValidationRule]] on the request item.

    item

    the invalid request item

    rule

    the rule description

  7. trait PRequestReader[R, A] extends AnyRef

    Permalink

    A polymorphic request reader (a reader monad) that reads a com.twitter.util.Future of A from the request of type R.

  8. class RequestError extends Exception

    Permalink

    A base exception of request reader.

  9. case class RequestErrors(errors: Seq[Throwable]) extends RequestError with Product with Serializable

    Permalink

    An exception that collects multiple request reader errors.

    An exception that collects multiple request reader errors.

    errors

    the errors collected from various request readers

  10. type RequestReader[A] = PRequestReader[Request, A]

    Permalink

    A PRequestReader with request type fixed to com.twitter.finagle.httpx.Request.

  11. trait ValidationRule[A] extends AnyRef

    Permalink

    A reusable validation rule that can be applied to any RequestReader with a matching type.

  12. type %>[A, B] = View[A, B]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.8.0) Custom request are deprecated

  13. trait ToRequest[R] extends AnyRef

    Permalink

    A type class that provides a conversion from some type to a com.twitter.finagle.httpx.Request.

    A type class that provides a conversion from some type to a com.twitter.finagle.httpx.Request.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.8.0) Custom request are deprecated

  14. trait View[A, B] extends AnyRef

    Permalink

    A reasonable and safe approach to implicit view A => B.

    A reasonable and safe approach to implicit view A => B.

    Annotations
    @implicitNotFound( ... ) @deprecated
    Deprecated

    (Since version 0.8.0) Custom request are deprecated

Value Members

  1. object DecodeRequest

    Permalink
  2. object PRequestReader

    Permalink
  3. object RequestReader

    Permalink

    Convenience methods for creating new reader instances.

  4. object ValidationRule

    Permalink

    Allows the creation of reusable validation rules for RequestReaders.

  5. def beGreaterThan[A](n: A)(implicit ev: Numeric[A]): ValidationRule[A]

    Permalink

    A ValidationRule that makes sure the numeric value is greater than given n.

  6. def beLessThan[A](n: A)(implicit ev: Numeric[A]): ValidationRule[A]

    Permalink

    A ValidationRule]] that makes sure the numeric value is less than given n.

  7. def beLongerThan(n: Int): ValidationRule[String]

    Permalink

    A ValidationRule]] that makes sure the string value is longer than n symbols.

  8. def beShorterThan(n: Int): ValidationRule[String]

    Permalink

    A ValidationRule]] that makes sure the string value is shorter than n symbols.

  9. val binaryBody: RequestReader[Array[Byte]]

    Permalink

    A RequestReader that reads a required binary request body, interpreted as a Array[Byte], or throws a NotPresent exception.

  10. val binaryBodyOption: RequestReader[Option[Array[Byte]]]

    Permalink

    A RequestReader that reads a binary request body, interpreted as a Array[Byte], into an Option.

  11. val body: RequestReader[String]

    Permalink

    A RequestReader that reads the required request body, interpreted as a String, or throws a NotPresent exception.

  12. val bodyOption: RequestReader[Option[String]]

    Permalink

    A RequestReader that reads an optional request body, interpreted as a String, into an Option.

  13. def cookie(name: String): RequestReader[Cookie]

    Permalink

    Creates a RequestReader that reads a required cookie from the request or raises a NotPresent exception when the cookie is missing.

    Creates a RequestReader that reads a required cookie from the request or raises a NotPresent exception when the cookie is missing.

    name

    the name of the cookie to read

    returns

    the cookie

  14. def cookieOption(name: String): RequestReader[Option[Cookie]]

    Permalink

    Creates a RequestReader that reads an optional HTTP cookie from the request into an Option.

    Creates a RequestReader that reads an optional HTTP cookie from the request into an Option.

    name

    the name of the cookie to read

    returns

    an Option that contains a cookie or None if the cookie does not exist on the request.

  15. def fileUpload(name: String): RequestReader[FileUpload]

    Permalink

    Creates a RequestReader that reads a required file upload from a multipart/form-data request.

    Creates a RequestReader that reads a required file upload from a multipart/form-data request.

    name

    the name of the parameter to read

    returns

    the file

  16. def fileUploadOption(name: String): RequestReader[Option[FileUpload]]

    Permalink

    Creates a RequestReader that reads an optional file upload from a multipart/form-data request into an Option.

    Creates a RequestReader that reads an optional file upload from a multipart/form-data request into an Option.

    name

    the name of the parameter to read

    returns

    an Option that contains the file or None is the parameter does not exist on the request.

  17. def header(name: String): RequestReader[String]

    Permalink

    Creates a RequestReader that reads a required HTTP header name from the request or raises a NotPresent exception when the header is missing.

    Creates a RequestReader that reads a required HTTP header name from the request or raises a NotPresent exception when the header is missing.

    name

    the header to read

    returns

    a header

  18. def headerOption(name: String): RequestReader[Option[String]]

    Permalink

    Creates a RequestReader that reads an optional HTTP header name from the request into an Option.

    Creates a RequestReader that reads an optional HTTP header name from the request into an Option.

    name

    the header to read

    returns

    an Option that contains a header value or None if the header is not present in the request

  19. object items

    Permalink

    Representations for the various types that can be processed with RequestReaders.

  20. def param(name: String): RequestReader[String]

    Permalink

    Creates a RequestReader that reads a required query-string param name from the request or raises a NotPresent exception when the param is missing; a NotValid exception is the param is empty.

    Creates a RequestReader that reads a required query-string param name from the request or raises a NotPresent exception when the param is missing; a NotValid exception is the param is empty.

    name

    the param name to read

    returns

    a param value

  21. def paramOption(name: String): RequestReader[Option[String]]

    Permalink

    Creates a RequestReader that reads an optional query-string param name from the request into an Option.

    Creates a RequestReader that reads an optional query-string param name from the request into an Option.

    name

    the param to read

    returns

    an Option that contains a param value or None if the param is empty

  22. def params(name: String): RequestReader[Seq[String]]

    Permalink

    Creates a RequestReader that reads an optional (in a meaning that a resulting Seq may be empty) multi-value query-string param name from the request into a Seq.

    Creates a RequestReader that reads an optional (in a meaning that a resulting Seq may be empty) multi-value query-string param name from the request into a Seq.

    name

    the param to read

    returns

    a Seq that contains all the values of multi-value param or an empty seq Nil if the params are missing or empty.

  23. def paramsNonEmpty(name: String): RequestReader[Seq[String]]

    Permalink

    Creates a RequestReader that reads a required (in a meaning that a resulting Seq will have at least one element) multi-value query-string param name from the request into a Seq or raises a NotPresent exception when the params are missing or empty.

    Creates a RequestReader that reads a required (in a meaning that a resulting Seq will have at least one element) multi-value query-string param name from the request into a Seq or raises a NotPresent exception when the params are missing or empty.

    name

    the param to read

    returns

    a Seq that contains all the values of multi-value param

  24. implicit def toOptionalInlineRule[A](fn: (A) ⇒ Boolean): (Option[A]) ⇒ Boolean

    Permalink

    Implicit conversion that allows the same inline rules to be used for required and optional values.

    Implicit conversion that allows the same inline rules to be used for required and optional values. If the optional value is non-empty, it gets validated (and validation may fail, producing error), but if it is empty, it is always treated as valid.

    In order to help the compiler determine the case when inline rule should be converted, the type of the validated value should be specified explicitly.

    paramOption("foo").should("be greater than 50") { i: Int => i > 50 }
    fn

    the underlying function to convert

Deprecated Value Members

  1. object ToRequest

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.8.0) Custom request are deprecated

  2. object View

    Permalink

    A companion object for View.

    A companion object for View.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.8.0) Custom request are deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped