akka/akka-http

Java DSL: Marshaller not usable to easily create HttpRequests

Offen

#2.128 geöffnet am 26.07.2018

 (0 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Scala (598 Forks)batch import
1 - triagedhelp wantedt:core

Repository-Metriken

Stars
 (1.311 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 10h) (2 gemergte PRs in 30 T)

Beschreibung

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...

Contributor Guide