io.finch

Endpoint

trait Endpoint[A] extends AnyRef

An Endpoint represents the HTTP endpoint.

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

An Endpoint transformation (map, embedFlatMap, 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 Mapper and Endpoint.apply method, which, depending on the argument type, delegates the map operation to the underlying function.

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 (or a space invader :+:) that takes two Endpoints and gives a coproduct Endpoint.

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 with Finagle HTTP.

Http.server.serve(foobar.toService)
Self Type
Endpoint[A]
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Endpoint
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def apply(input: Input): Option[(Input, () ⇒ Future[Output[A]])]

    Extracts some value of type A from the given input.

Concrete Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def /[B](that: Endpoint[B])(implicit adjoin: PairAdjoin[A, B]): Endpoint[PairAdjoin.Out]

    Composes this endpoint with the given that endpoint.

    Composes this endpoint with the given that endpoint. The resulting endpoint will succeed only if both this and that endpoints succeed.

  5. def :+:[B](that: Endpoint[B])(implicit adjoin: Adjoin[:+:[B, :+:[A, CNil]]]): Endpoint[shapeless.ops.adjoin.Adjoin.Out]

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

  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. def ?[B](that: RequestReader[B])(implicit adjoin: PairAdjoin[A, B]): Endpoint[PairAdjoin.Out]

    Composes this endpoint with the given RequestReader.

  9. def ap[B](fn: Endpoint[(A) ⇒ B]): Endpoint[B]

    Maps this endpoint to Endpoint[A => B].

  10. def apply(mapper: Mapper[A]): Endpoint[Out]

    Maps this endpoint to either A => Output[B] or A => Output[Future[B]].

  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. def embedFlatMap[B](fn: (A) ⇒ Future[B]): Endpoint[B]

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

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

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

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

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

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

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

  19. def hashCode(): Int

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

    Definition Classes
    Any
  21. def map[B](fn: (A) ⇒ B): Endpoint[B]

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

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

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

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

    Definition Classes
    AnyRef
  25. def rescue[B >: A](pf: PartialFunction[Throwable, Future[Output[B]]]): Endpoint[B]

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

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

    Definition Classes
    AnyRef
  27. def toService(implicit ts: ToService[A]): Service[Request, Response]

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

  28. def toString(): String

    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. def withCharset(charset: Option[String]): Endpoint[A]

  33. def withContentType(contentType: Option[String]): Endpoint[A]

  34. def withCookie(cookie: Cookie): Endpoint[A]

  35. def withFilter(p: (A) ⇒ Boolean): Endpoint[A]

  36. def withHeader(header: (String, String)): Endpoint[A]

  37. def |[B >: A](that: Endpoint[B]): Endpoint[B]

    Sequentially composes this endpoint with the given that endpoint.

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

Inherited from AnyRef

Inherited from Any

Ungrouped