Trait/Object

io.finch

Endpoint

Related Docs: object Endpoint | package finch

Permalink

trait Endpoint[F[_], 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 internal.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" :: path[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[F, 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[F, 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[F, B])(implicit a: Adjoin[:+:[B, :+:[A, CNil]]], F: MonadError[F, Throwable]): Endpoint[F, 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[F, B])(implicit pa: PairAdjoin[B, A], F: MonadError[F, Throwable]): Endpoint[F, 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. final def attempt(implicit F: MonadError[F, Throwable]): Endpoint[F, Either[Throwable, A]]

    Permalink

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

  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def compile(implicit F: MonadError[F, Throwable], tr: ToResponse.Aux[F, A, Json], tre: ToResponse.Aux[F, Exception, Json]): Compiled[F]

    Permalink

    Converts this endpoint to Endpoint.Compiled[F] what is efficiently is Kleisli[F, Request, Response] where responses are encoded with JSON encoder.

    Converts this endpoint to Endpoint.Compiled[F] what is efficiently is Kleisli[F, Request, Response] where responses are encoded with JSON encoder.

    Consider using io.finch.Bootstrap instead

  10. final def compileAs[CT <: String](implicit F: MonadError[F, Throwable], tr: ToResponse.Aux[F, A, CT], tre: ToResponse.Aux[F, Exception, CT]): Compiled[F]

    Permalink

    Converts this endpoint to Endpoint.Compiled[F] what is efficiently is Kleisli[F, Request, Response] where responses are encoded with encoder corresponding to CT Content-Type.

    Converts this endpoint to Endpoint.Compiled[F] what is efficiently is Kleisli[F, Request, Response] where responses are encoded with encoder corresponding to CT Content-Type.

    Consider using io.finch.Bootstrap instead

  11. final def coproduct[B >: A](other: Endpoint[F, B]): Endpoint[F, 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.

    Matching Rules

    - if both endpoints match, the result with a shorter remainder (in terms of consumed route) is picked - if both endpoints don't match, the more specific result (explaining the reason for not matching) is picked

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

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def handle(pf: PartialFunction[Throwable, Output[A]])(implicit F: ApplicativeError[F, Throwable]): Endpoint[F, A]

    Permalink

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

  17. def hashCode(): Int

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

    Permalink
    Definition Classes
    Any
  19. def item: RequestItem

    Permalink

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

  20. final def map[B](fn: (A) ⇒ B)(implicit F: Monad[F]): Endpoint[F, B]

    Permalink

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

  21. final def mapAsync[B](fn: (A) ⇒ F[B])(implicit F: Monad[F]): Endpoint[F, B]

    Permalink

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

  22. final def mapOutput[B](fn: (A) ⇒ Output[B])(implicit F: MonadError[F, Throwable]): Endpoint[F, B]

    Permalink

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

  23. final def mapOutputAsync[B](fn: (A) ⇒ F[Output[B]])(implicit F: Monad[F]): Endpoint[F, B]

    Permalink

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  27. final def product[B](other: Endpoint[F, B])(implicit F: MonadError[F, Throwable]): Endpoint[F, (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., io.finch.Errors) into io.finch.Errors) and will fail-fast with the first non-Finch error (just ordinary Exception) observed.

  28. final def productWith[B, O](other: Endpoint[F, B])(p: (A, B) ⇒ O)(implicit F: MonadError[F, Throwable]): Endpoint[F, 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.

  29. final def rescue(pf: PartialFunction[Throwable, F[Output[A]]])(implicit F: ApplicativeError[F, Throwable]): Endpoint[F, A]

    Permalink

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

  30. final def should(rule: ValidationRule[A])(implicit F: MonadError[F, Throwable]): Endpoint[F, 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.

  31. final def should(rule: String)(predicate: (A) ⇒ Boolean)(implicit F: MonadError[F, Throwable]): Endpoint[F, 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.

  32. final def shouldNot(rule: ValidationRule[A])(implicit F: MonadError[F, Throwable]): Endpoint[F, 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.

  33. final def shouldNot(rule: String)(predicate: (A) ⇒ Boolean)(implicit F: MonadError[F, Throwable]): Endpoint[F, 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.

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

    Permalink
    Definition Classes
    AnyRef
  35. final def toService(implicit F: Effect[F], tr: ToResponse.Aux[F, A, Json], tre: ToResponse.Aux[F, 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 io.finch.Bootstrap instead.

  36. final def toServiceAs[CT <: String](implicit F: Effect[F], tr: ToResponse.Aux[F, A, CT], tre: ToResponse.Aux[F, 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 io.finch.Bootstrap instead.

  37. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  38. final def transform[B](fn: (F[A]) ⇒ F[B])(implicit F: Monad[F]): Endpoint[F, B]

    Permalink

    Transform this endpoint to the given function F[A] => F[B]

  39. final def transformOutput[B](fn: (F[Output[A]]) ⇒ F[Output[B]]): Endpoint[F, B]

    Permalink

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

    Transforms this endpoint to the given function F[Output[A]] => F[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))
  40. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def withToString(ts: ⇒ String): Endpoint[F, A]

    Permalink

    Overrides the toString method on this endpoint.

Deprecated Value Members

  1. final def transformF[B](fn: (F[A]) ⇒ F[B])(implicit F: Monad[F]): Endpoint[F, B]

    Permalink

    Transform this endpoint to the given function F[A] => F[B]

    Transform this endpoint to the given function F[A] => F[B]

    Annotations
    @deprecated
    Deprecated

    (Since version 0.29) Use .transform instead

Inherited from AnyRef

Inherited from Any

Ungrouped