io.finch

request

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., RequiredParam, OptionalParam) 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) ~> 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)) ~> User
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. request
  2. LowPriorityRequestReaderImplicits
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

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

    A symbolic alias for View.

  2. trait DecodeAnyRequest extends AnyRef

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

  3. trait DecodeMagnet[A] extends AnyRef

    A magnet that wraps a DecodeRequest.

  4. trait DecodeRequest[+A] extends AnyRef

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

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

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

  6. trait LowPriorityRequestReaderImplicits extends AnyRef

    Trait with low-priority implicits to avoid conflicts that would arise from adding implicits that would work with any type in the same scope as implicits for concrete types.

    Trait with low-priority implicits to avoid conflicts that would arise from adding implicits that would work with any type in the same scope as implicits for concrete types.

    Implicits defined in super-types have lower priority than those defined in a sub-type. Therefore we define low- priority implicits here and mix this trait into the package object.

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

    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

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

    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

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

    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

  10. implicit final class OptionReaderOps[R, A] extends AnyVal

    Implicit conversion that adds convenience methods to readers for optional values.

  11. trait PRequestReader[R, A] extends AnyRef

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

  12. class RequestError extends Exception

    A base exception of request reader.

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

    An exception that collects multiple request reader errors.

    An exception that collects multiple request reader errors.

    errors

    the errors collected from various request readers

  14. type RequestReader[A] = PRequestReader[HttpRequest, A]

    A PRequestReader with request type fixed to HttpRequest.

  15. implicit class RrArrow1[R, A] extends AnyRef

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of one argument.

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of one argument.

    Definition Classes
    LowPriorityRequestReaderImplicits
  16. implicit final class RrArrow2[R, A, B] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of two arguments.

  17. implicit final class RrArrow3[R, A, B, C] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of three arguments.

  18. implicit final class RrArrow4[R, A, B, C, D] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of four arguments.

  19. implicit final class RrArrow5[R, A, B, C, D, E] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of five arguments.

  20. implicit final class RrArrow6[R, A, B, C, D, E, F] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of six arguments.

  21. implicit final class RrArrow7[R, A, B, C, D, E, F, G] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of seven arguments.

  22. implicit final class RrArrow8[R, A, B, C, D, E, F, G, H] extends AnyVal

    Adds a ~> and ~~> compositors to RequestReader to compose it with function of eight arguments.

  23. implicit final class StringOptionReaderOps[R] extends AnyVal

    Implicit conversion that allows to call as[A] on any RequestReader[Option[String]] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    Implicit conversion that allows to call as[A] on any RequestReader[Option[String]] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    The resulting reader will fail when the result is non-empty and type conversion fails. It will succeed if the result is empty or type conversion succeeds.

  24. implicit final class StringReaderOps[R] extends AnyVal

    Implicit conversion that allows to call as[A] on any RequestReader[String] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    Implicit conversion that allows to call as[A] on any RequestReader[String] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    The resulting reader will fail when type conversion fails.

  25. implicit class StringSeqReaderOps[R] extends AnyRef

    Implicit conversion that allows to call as[A] on any RequestReader[Seq[String]] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    Implicit conversion that allows to call as[A] on any RequestReader[Seq[String]] to perform a type conversion based on an implicit DecodeRequest[A] which must be in scope.

    The resulting reader will fail when the result is non-empty and type conversion fails on one or more of the elements in the Seq. It will succeed if the result is empty or type conversion succeeds for all elements.

  26. trait ValidationRule[A] extends AnyRef

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

  27. trait View[A, B] extends AnyRef

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

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

    Annotations
    @implicitNotFound( ... )
  28. case class ~[+A, +B](_1: A, _2: B) extends Product with Serializable

    A wrapper for two result values.

Value Members

  1. object DecodeRequest

    Convenience method for creating new DecodeRequest instances.

  2. object RequestReader

    Convenience methods for creating new reader instances.

  3. object ValidationRule

    Allows the creation of reusable validation rules for RequestReaders.

  4. object View

    A companion object for View.

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

    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]

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

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

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

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

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

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

    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]]]

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

  11. val body: RequestReader[String]

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

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

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

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

    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]]

    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. implicit val decodeBoolean: DecodeRequest[Boolean]

    A DecodeRequest instance for Boolean.

  16. implicit val decodeDouble: DecodeRequest[Double]

    A DecodeRequest instance for Double.

  17. implicit val decodeFloat: DecodeRequest[Float]

    A DecodeRequest instance for Float.

  18. implicit val decodeInt: DecodeRequest[Int]

    A DecodeRequest instance for Int.

  19. implicit val decodeLong: DecodeRequest[Long]

    A DecodeRequest instance for Long.

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

    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

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

    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.

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

    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

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

    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

  24. object items

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

  25. implicit def magnetFromAnyDecode[A](implicit d: DecodeAnyRequest, tag: ClassTag[A]): DecodeMagnet[A]

    Creates a DecodeMagnet from DecodeAnyRequest.

  26. implicit def magnetFromDecode[A](implicit d: DecodeRequest[A]): DecodeMagnet[A]

    Creates a DecodeMagnet from DecodeRequest.

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

    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

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

    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

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

    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.

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

    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

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

    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.

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

    the underlying function to convert

  32. implicit def toOptionalRule[A](rule: ValidationRule[A]): ValidationRule[Option[A]]

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

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

    rule

    the validation rule to adapt for optional values

    returns

    a new validation rule that applies the specified rule to an optional value in case it is not empty

Deprecated Value Members

  1. val OptionalBinaryBody: RequestReader[Option[Array[Byte]]]

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

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use binaryBodyOption instead.

  2. val OptionalBody: RequestReader[Option[String]]

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

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use bodyOption instead.

  3. def OptionalCookie(name: String): RequestReader[Option[Cookie]]

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

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

    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.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use cookieOption(name) instead.

  4. def OptionalHeader(name: String): RequestReader[Option[String]]

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

    Creates a RequestReader that reads an optional string header 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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use headerOption(name) instead.

  5. def OptionalParam(param: String): RequestReader[Option[String]]

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

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

    param

    the param to read

    returns

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use paramOption(name) instead

  6. def OptionalParams(param: String): RequestReader[Seq[String]]

    Creates a RequestReader that reads an optional multi-value string param from the request into a Seq.

    Creates a RequestReader that reads an optional multi-value string param from the request into a Seq.

    param

    the param to read

    returns

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use params(name) instead.

  7. val RequiredBinaryBody: RequestReader[Array[Byte]]

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

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use binaryBody instead.

  8. val RequiredBody: RequestReader[String]

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

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use body instead.

  9. def RequiredCookie(cookie: String): RequestReader[Cookie]

    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.

    cookie

    the name of the cookie to read

    returns

    the cookie

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use cookie(name) instead.

  10. def RequiredHeader(name: String): RequestReader[String]

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

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

    name

    the header to read

    returns

    a header

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use header(name) instead.

  11. def RequiredParam(name: String): RequestReader[String]

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

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

    name

    the param name to read

    returns

    a param value

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use param(name) instead

  12. def RequiredParams(param: String): RequestReader[Seq[String]]

    Creates a RequestReader that reads a required multi-value string param from the request into a Seq or raises a NotPresent exception when the param is missing or empty.

    Creates a RequestReader that reads a required multi-value string param from the request into a Seq or raises a NotPresent exception when the param is missing or empty.

    param

    the param to read

    returns

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use paramsNonEmpty(name) instead.

Inherited from AnyRef

Inherited from Any

Ungrouped