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" :: path[String]) { s: String => Ok(Bar(s)) }
Endpoint
s are also composable in terms of or-else combinator (known as a "space invader"
operator :+:
) that takes two Endpoint
s 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]
- Source
- Endpoint.scala
- Alphabetic
- By Inheritance
- Endpoint
- AnyRef
- Any
- by OptionEndpointOps
- by HListEndpointOps
- by ValueEndpointOps
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (Endpoint[A], B)
-
final
def
:+:[B](that: Endpoint[B])(implicit a: Adjoin[:+:[B, :+:[A, CNil]]]): Endpoint[shapeless.ops.adjoin.Adjoin.Out]
Composes this endpoint with another in such a way that coproducts are flattened.
-
final
def
::[B](other: Endpoint[B])(implicit pa: PairAdjoin[B, A]): Endpoint[internal.PairAdjoin.Out]
Composes this endpoint with the given Endpoint.
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
as[A](implicit gen: Aux[A, A]): Endpoint[A]
Converts this endpoint to one that returns any type with this shapeless.HList as its representation.
Converts this endpoint to one that returns any type with this shapeless.HList as its representation.
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to HListEndpointOps[A] performed by method HListEndpointOps in io.finch.Endpoint. This conversion will take place only if A is a subclass of HList (A <: HList).
- Definition Classes
- HListEndpointOps
-
def
as[A](implicit gen: Aux[A, ::[A, HNil]]): Endpoint[A]
Converts this endpoint to one that returns any type with
B :: HNil
as its representation.Converts this endpoint to one that returns any type with
B :: HNil
as its representation.- Implicit
- This member is added by an implicit conversion from Endpoint[A] to ValueEndpointOps[A] performed by method ValueEndpointOps in io.finch.Endpoint.
- Definition Classes
- ValueEndpointOps
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
asTuple(implicit t: Tupler[A]): Endpoint[shapeless.ops.hlist.Tupler.Out]
Converts this endpoint to one that returns a tuple with the same types as this shapeless.HList.
Converts this endpoint to one that returns a tuple with the same types as this shapeless.HList.
Note that this will fail at compile time if this this shapeless.HList contains more than 22 elements.
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to HListEndpointOps[A] performed by method HListEndpointOps in io.finch.Endpoint. This conversion will take place only if A is a subclass of HList (A <: HList).
- Definition Classes
- HListEndpointOps
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
coproduct[B >: A](other: Endpoint[B]): Endpoint[B]
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 orthat
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
- def ensuring(cond: (Endpoint[A]) ⇒ Boolean, msg: ⇒ Any): Endpoint[A]
- def ensuring(cond: (Endpoint[A]) ⇒ Boolean): Endpoint[A]
- def ensuring(cond: Boolean, msg: ⇒ Any): Endpoint[A]
- def ensuring(cond: Boolean): Endpoint[A]
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def formatted(fmtstr: String): String
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
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.
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
item: RequestItem
Request item (part) that's this endpoint work with.
-
final
def
liftToTry: Endpoint[Try[A]]
Lifts this endpoint into one that always succeeds, with Try representing both success and failure cases.
-
final
def
map[B](fn: (A) ⇒ B): Endpoint[B]
Maps this endpoint to the given function
A => B
. -
final
def
mapAsync[B](fn: (A) ⇒ Future[B]): Endpoint[B]
Maps this endpoint to the given function
A => Future[B]
. -
final
def
mapOutput[B](fn: (A) ⇒ Output[B]): Endpoint[B]
Maps this endpoint to the given function
A => Output[B]
. -
final
def
mapOutputAsync[B](fn: (A) ⇒ Future[Output[B]]): Endpoint[B]
Maps this endpoint to the given function
A => Future[Output[B]]
. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
orElse[B >: A](alternative: ⇒ Option[B]): Endpoint[Option[B]]
If endpoint is empty it will return provided alternative.
If endpoint is empty it will return provided alternative.
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to OptionEndpointOps[A] performed by method OptionEndpointOps in io.finch.Endpoint. This conversion will take place only if A is Option[A] (A =:= Option[A]).
- Definition Classes
- OptionEndpointOps
-
final
def
product[B](other: Endpoint[B]): Endpoint[(A, B)]
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 ordinaryException
) observed. -
final
def
productWith[B, O](other: Endpoint[B])(p: (A, B) ⇒ O): Endpoint[O]
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. -
final
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.
-
final
def
should(rule: ValidationRule[A]): Endpoint[A]
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.
-
final
def
should(rule: String)(predicate: (A) ⇒ Boolean): Endpoint[A]
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.
-
final
def
shouldNot(rule: ValidationRule[A]): Endpoint[A]
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.
-
final
def
shouldNot(rule: String)(predicate: (A) ⇒ Boolean): Endpoint[A]
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.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
toService(implicit tr: ToResponse.Aux[A, Json], tre: ToResponse.Aux[Exception, Json]): Service[Request, Response]
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.
-
final
def
toServiceAs[CT <: String](implicit tr: ToResponse.Aux[A, CT], tre: ToResponse.Aux[Exception, CT]): Service[Request, Response]
Converts this endpoint to a Finagle service
Request => Future[Response]
that serves custom content-typeCT
.Converts this endpoint to a Finagle service
Request => Future[Response]
that serves custom content-typeCT
.Consider using Bootstrap instead.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
transform[B](fn: (Future[Output[A]]) ⇒ Future[Output[B]]): Endpoint[B]
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))
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withDefault[B >: A](default: ⇒ B): Endpoint[B]
If endpoint is empty it will return provided default value.
If endpoint is empty it will return provided default value.
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to OptionEndpointOps[A] performed by method OptionEndpointOps in io.finch.Endpoint. This conversion will take place only if A is Option[A] (A =:= Option[A]).
- Definition Classes
- OptionEndpointOps
-
final
def
withToString(ts: ⇒ String): Endpoint[A]
Overrides the
toString
method on this endpoint. - def →[B](y: B): (Endpoint[A], B)
Shadowed Implicit Value Members
-
val
self: Endpoint[Option[A]]
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to OptionEndpointOps[A] performed by method OptionEndpointOps in io.finch.Endpoint. This conversion will take place only if A is Option[A] (A =:= Option[A]).
- Shadowing
- This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
To access this member you can use a type ascription:(endpoint: OptionEndpointOps[A]).self
- Definition Classes
- OptionEndpointOps
-
val
self: Endpoint[A]
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to HListEndpointOps[A] performed by method HListEndpointOps in io.finch.Endpoint. This conversion will take place only if A is a subclass of HList (A <: HList).
- Shadowing
- This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
To access this member you can use a type ascription:(endpoint: HListEndpointOps[A]).self
- Definition Classes
- HListEndpointOps
-
val
self: Endpoint[A]
- Implicit
- This member is added by an implicit conversion from Endpoint[A] to ValueEndpointOps[A] performed by method ValueEndpointOps in io.finch.Endpoint.
- Shadowing
- This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
To access this member you can use a type ascription:(endpoint: ValueEndpointOps[A]).self
- Definition Classes
- ValueEndpointOps
This is the API documentation for finch
Finch is a thin layer of purely functional basic blocks atop of [Finagle][finagle] for building composable HTTP APIs. Its mission is to provide the developers simple and robust HTTP primitives being as close as possible to the bare metal Finagle API.
Finch uses multi-project structure and contains of the following _modules_:
Please refer to the documentation for a more detailed introduction to the library.