diff --git a/core/src/main/scala/io/finch/Endpoint.scala b/core/src/main/scala/io/finch/Endpoint.scala index 1586b7670..e406cd908 100644 --- a/core/src/main/scala/io/finch/Endpoint.scala +++ b/core/src/main/scala/io/finch/Endpoint.scala @@ -889,21 +889,54 @@ object Endpoint { } /** + * An [[Endpoint]] that matches chunked requests and lifts their content into a generic + * **binary** stream passed as a type parameter. This method, along with other `bodyStream` + * endpoints, are integration points with streaming libraries such as fs2 and iteratee. * + * {{{ + * scala> import io.finch._, io.finch.iteratee._, cats.effect.IO, io.iteratee.Enumerator + * + * scala> val bin = Endpoint[IO].binaryBodyStream[Enumerator] + * bin: Endpoint[IO, Enumerator[IO, Array[Byte]]] = binaryBodyStream + * }}} */ def binaryBodyStream[F[_]: Effect, S[_[_], _]](implicit LR: LiftReader[S, F] ): Endpoint[F, S[F, Array[Byte]]] = new BinaryBodyStream[F, S] /** + * An [[Endpoint]] that matches chunked requests and lifts their content into a generic + * **string** stream passed as a type parameter. This method, along with other `bodyStream` + * endpoints, are integration points with streaming libraries such as fs2 and iteratee. * + * {{{ + * scala> import io.finch._, io.finch.iteratee._, cats.effect.IO, io.iteratee.Enumerator + * + * scala> val bin = Endpoint[IO].stringBodyStream[Enumerator] + * bin: Endpoint[IO, Enumerator[IO, String]] = stringBodyStream + * }}} */ def stringBodyStream[F[_]: Effect, S[_[_], _]](implicit LR: LiftReader[S, F] ): Endpoint[F, S[F, String]] = new StringBodyStream[F, S] /** + * An [[Endpoint]] that matches chunked requests and lifts their content into a generic + * stream passed as a type parameter. This method, along with other `bodyStream` + * endpoints, are integration points with streaming libraries such as fs2 and iteratee. + * + * When, for example, JSON library is import, this endpoint can parse an inbound JSON stream. * + * {{{ + * scala> import io.finch._, io.finch.iteratee._, cats.effect.IO, io.iteratee.Enumerator + * + * scala> import io.finch.circe._, io.circe.generic.auto._ + * + * scala> case class Foo(s: String) + + * scala> val json = Endpoint[IO].bodyStream[Enumerator, Foo, Application.Json] + * bin: Endpoint[IO, Enumerator[IO, Foo]] = bodyStream + * }}} */ def bodyStream[F[_]: Effect, S[_[_], _], A, CT <: String](implicit LR: LiftReader[S, F], @@ -911,7 +944,7 @@ object Endpoint { ): Endpoint[F, S[F, A]] = new BodyStream[F, S, A, CT] /** - * + * See [[bodyStream]]. This is just an alias for `bodyStream[?, ?, Application.Json]`. */ def jsonBodyStream[F[_]: Effect, S[_[_], _], A](implicit LR: LiftReader[S, F], @@ -919,7 +952,7 @@ object Endpoint { ) : Endpoint[F, S[F, A]] = bodyStream[F, S, A, Application.Json] /** - * + * See [[bodyStream]]. This is just an alias for `bodyStream[?, ?, Text.Plain]`. */ def textBodyStream[F[_]: Effect, S[_[_], _], A](implicit LR: LiftReader[S, F], diff --git a/core/src/main/scala/io/finch/EndpointModule.scala b/core/src/main/scala/io/finch/EndpointModule.scala index 27b7f673b..3d5f7451d 100644 --- a/core/src/main/scala/io/finch/EndpointModule.scala +++ b/core/src/main/scala/io/finch/EndpointModule.scala @@ -290,7 +290,7 @@ trait EndpointModule[F[_]] { Endpoint.asyncBody[F] /** - * + * An alias for [[Endpoint.binaryBodyStream]]. */ def binaryBodyStream[S[_[_], _]](implicit F: Effect[F], @@ -298,7 +298,7 @@ trait EndpointModule[F[_]] { ): Endpoint[F, S[F, Array[Byte]]] = Endpoint.binaryBodyStream[F, S] /** - * + * An alias for [[Endpoint.stringBodyStream]]. */ def stringBodyStream[S[_[_], _]](implicit F: Effect[F], @@ -306,7 +306,7 @@ trait EndpointModule[F[_]] { ): Endpoint[F, S[F, String]] = Endpoint.stringBodyStream[F, S] /** - * + * An alias for [[Endpoint.bodyStream]]. */ def bodyStream[S[_[_], _], A, CT <: String](implicit F: Effect[F], @@ -315,7 +315,7 @@ trait EndpointModule[F[_]] { ): Endpoint[F, S[F, A]] = Endpoint.bodyStream[F, S, A, CT] /** - * + * An alias for [[Endpoint.jsonBodyStream]]. */ def jsonBodyStream[S[_[_], _], A](implicit F: Effect[F], @@ -324,7 +324,7 @@ trait EndpointModule[F[_]] { ): Endpoint[F, S[F, A]] = Endpoint.jsonBodyStream[F, S, A] /** - * + * An alias for [[Endpoint.textBodyStream]]. */ def textBodyStream[S[_[_], _], A](implicit F: Effect[F], diff --git a/core/src/main/scala/io/finch/endpoint/body.scala b/core/src/main/scala/io/finch/endpoint/body.scala index 8bb505837..cfac6a3d4 100644 --- a/core/src/main/scala/io/finch/endpoint/body.scala +++ b/core/src/main/scala/io/finch/endpoint/body.scala @@ -136,4 +136,6 @@ private[finch] final class BodyStream[F[_], S[_[_], _], A, CT <: String](implici protected def prepare(r: Reader[Buf], cs: Charset): Output[S[F, A]] = Output.payload(A(LR(r), cs)) + + override def toString: String = "bodyStream" }