Trait/Object

io.finch

Endpoint

Related Docs: object Endpoint | package finch

Permalink

trait Endpoint[A] extends AnyRef

An Endpoint represents the HTTP endpoint.

It is well known and widely adopted in Finagle that "Your Server is a Function" (i.e., Request => Future[Response]). In a REST/HTTP API setting this function may be viewed as Request =1=> (A =2=> Future[B]) =3=> Future[Response], where transformation 1 is a request decoding (deserialization), transformation 2 - is a business logic and transformation 3 is - a response encoding (serialization). The only interesting part here is transformation 2 (i.e., A => Future[B]), which represents an application business.

An Endpoint transformation (map, mapAsync, etc.) encodes the business logic, while the rest of Finch ecosystem takes care about both serialization and deserialization.

A typical way to transform (or map) the Endpoint is to use io.finch.syntax.Mapper:

import io.finch._

case class Foo(i: Int)
case class Bar(s: String)

val foo: Endpoint[Foo] = get("foo") { Ok(Foo(42)) }
val bar: Endpoint[Bar] = get("bar" :: string) { s: String => Ok(Bar(s)) }

Endpoints are also composable in terms of or-else combinator (known as a "space invader" operator :+:) that takes two Endpoints and returns a coproduct Endpoint.

import io.finch._

val foobar: Endpoint[Foo :+: Bar :+: CNil] = foo :+: bar

An Endpoint might be converted into a Finagle Service with Endpoint.toService method so it can be served within Finagle HTTP.

import com.twitter.finagle.Http

Http.server.serve(foobar.toService)
Self Type
Endpoint[A]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Endpoint
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def apply(input: Input): Result[A]

    Permalink

    Runs this endpoint.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def :+:[B](that: Endpoint[B])(implicit a: Adjoin[:+:[B, :+:[A, CNil]]]): Endpoint[shapeless.ops.adjoin.Adjoin.Out]

    Permalink

    Composes this endpoint with another in such a way that coproducts are flattened.

  4. final def ::[B](other: Endpoint[B])(implicit pa: PairAdjoin[B, A]): Endpoint[internal.PairAdjoin.Out]

    Permalink

    Composes this endpoint with the given Endpoint.

  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def coproduct[B >: A](other: Endpoint[B]): Endpoint[B]

    Permalink

    Sequentially composes this endpoint with the given other endpoint.

    Sequentially composes this endpoint with the given other endpoint. The resulting endpoint will succeed if either this or that endpoints are succeed.

  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def handle[B >: A](pf: PartialFunction[Throwable, Output[B]]): Endpoint[B]

    Permalink

    Recovers from any exception occurred in this endpoint by creating a new endpoint that will handle any matching throwable from the underlying future.

  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. def item: RequestItem

    Permalink

    Request item (part) that's this endpoint work with.

  17. final def liftToTry: Endpoint[Try[A]]

    Permalink

    Lifts this endpoint into one that always succeeds, with Try representing both success and failure cases.

  18. final def map[B](fn: (A) ⇒ B): Endpoint[B]

    Permalink

    Maps this endpoint to the given function A => B.

  19. final def mapAsync[B](fn: (A) ⇒ Future[B]): Endpoint[B]

    Permalink

    Maps this endpoint to the given function A => Future[B].

  20. final def mapOutput[B](fn: (A) ⇒ Output[B]): Endpoint[B]

    Permalink

    Maps this endpoint to the given function A => Output[B].

  21. final def mapOutputAsync[B](fn: (A) ⇒ Future[Output[B]]): Endpoint[B]

    Permalink

    Maps this endpoint to the given function A => Future[Output[B]].

  22. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def product[B](other: Endpoint[B]): Endpoint[(A, B)]

    Permalink

    Returns a product of this and other endpoint.

    Returns a product of this and other endpoint. The resulting endpoint returns a tuple of both values.

    This combinator is an important piece for Finch's error accumulation. In its current form, product will accumulate Finch's own errors (i.e., Errors) into Errors) and will fail-fast with the first non-Finch error (just ordinary Exception) observed.

  26. final def productWith[B, O](other: Endpoint[B])(p: (A, B) ⇒ O): Endpoint[O]

    Permalink

    Returns a product of this and other endpoint.

    Returns a product of this and other endpoint. The resulting endpoint returns a value of resulting type for product function.

  27. final def rescue[B >: A](pf: PartialFunction[Throwable, Future[Output[B]]]): Endpoint[B]

    Permalink

    Recovers from any exception occurred in this endpoint by creating a new endpoint that will handle any matching throwable from the underlying future.

  28. final def should(rule: ValidationRule[A]): Endpoint[A]

    Permalink

    Validates the result of this endpoint using a predefined rule.

    Validates the result of this endpoint using a predefined rule. This method allows for rules to be reused across multiple endpoints.

    rule

    the predefined ValidationRule that will return true if the data is valid

    returns

    an endpoint that will return the value of this reader if it is valid. Otherwise the future fails with an Error.NotValid error.

  29. final def should(rule: String)(predicate: (A) ⇒ Boolean): Endpoint[A]

    Permalink

    Validates the result of this endpoint using a predicate.

    Validates the result of this endpoint using a predicate. The rule is used for error reporting.

    rule

    text describing the rule being validated

    predicate

    returns true if the data is valid

    returns

    an endpoint that will return the value of this reader if it is valid. Otherwise the future fails with an Error.NotValid error.

  30. final def shouldNot(rule: ValidationRule[A]): Endpoint[A]

    Permalink

    Validates the result of this endpoint using a predefined rule.

    Validates the result of this endpoint using a predefined rule. This method allows for rules to be reused across multiple endpoints.

    rule

    the predefined ValidationRule that will return false if the data is valid

    returns

    an endpoint that will return the value of this reader if it is valid. Otherwise the future fails with a Error.NotValid error.

  31. final def shouldNot(rule: String)(predicate: (A) ⇒ Boolean): Endpoint[A]

    Permalink

    Validates the result of this endpoint using a predicate.

    Validates the result of this endpoint using a predicate. The rule is used for error reporting.

    rule

    text describing the rule being validated

    predicate

    returns false if the data is valid

    returns

    an endpoint that will return the value of this reader if it is valid. Otherwise the future fails with a Error.NotValid error.

  32. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  33. final def toService(implicit tr: ToResponse.Aux[A, Json], tre: ToResponse.Aux[Exception, Json]): Service[Request, Response]

    Permalink

    Converts this endpoint to a Finagle service Request => Future[Response] that serves JSON.

    Converts this endpoint to a Finagle service Request => Future[Response] that serves JSON.

    Consider using Bootstrap instead.

  34. final def toServiceAs[CT <: String](implicit tr: ToResponse.Aux[A, CT], tre: ToResponse.Aux[Exception, CT]): Service[Request, Response]

    Permalink

    Converts this endpoint to a Finagle service Request => Future[Response] that serves custom content-type CT.

    Converts this endpoint to a Finagle service Request => Future[Response] that serves custom content-type CT.

    Consider using Bootstrap instead.

  35. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  36. final def transform[B](fn: (Future[Output[A]]) ⇒ Future[Output[B]]): Endpoint[B]

    Permalink

    Transforms this endpoint to the given function Future[Output[A]] => Future[Output[B]].

    Transforms this endpoint to the given function Future[Output[A]] => Future[Output[B]].

    Might be useful to perform some extra action on the underlying Future. For example, time the latency of the given endpoint.

    import io.finch._
    import com.twitter.finagle.stats._
    
    def time[A](stat: Stat, e: Endpoint[A]): Endpoint[A] =
      e.transform(f => Stat.timeFuture(s)(f))
  37. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def withCharset(charset: Charset): Endpoint[A]

    Permalink
  41. final def withCookie(cookie: Cookie): Endpoint[A]

    Permalink
  42. final def withHeader(header: (String, String)): Endpoint[A]

    Permalink
  43. final def withToString(ts: ⇒ String): Endpoint[A]

    Permalink

    Overrides the toString method on this endpoint.

Inherited from AnyRef

Inherited from Any

Ungrouped