akka/akka-http

Java DSL: Marshaller not usable to easily create HttpRequests

オープン

#2,128 opened on 2018/07/26

 (0 件のコメント) (1 件のリアクション) (0 人の担当者)Scala (598 件のフォーク)batch import
1 - triagedhelp wantedt:core

Repository metrics

Stars
 (1,311 個のスター)
PR merge metrics
 (平均マージ 1d 10h) (30d で 2 merged PRs)

説明

Goes hand in hand with the fact that we don't really provide a high level user API for the http client.

Something among the lines of

class Marshaller[-A, +B] private (implicit val asScala: marshalling.Marshaller[A, B]) {
  import Marshaller.fromScala

  /** INTERNAL API: involves unsafe cast (however is very fast) */
  // TODO would be nice to not need this special case
  @InternalApi
  private[akka] def asScalaCastOutput[C]: marshalling.Marshaller[A, C] = asScala.asInstanceOf[marshalling.Marshaller[A, C]]

  def map[C](f: function.Function[B @uncheckedVariance, C]): Marshaller[A, C] = fromScala(asScala.map(f.apply))

  def compose[C](f: function.Function[C, A @uncheckedVariance]): Marshaller[C, B] = fromScala(asScala.compose(f.apply))

  // new 
  def marshal(value: A, system: ActorSystem) =
    marshal(value, system.dispatcher)

  // new 
  def marshal(value: A, dispatcher: ExecutionContext): CompletionStage[util.List[Marshalling[B]]] = {
    import scala.collection.JavaConverters._
    import scala.compat.java8.FutureConverters._
    val res: Future[List[Marshalling[B]]] = asScala.apply(value)(dispatcher)
    res.map(_.asJava)(dispatcher).toJava
  }

}

could be a start...

コントリビューターガイド