akka/akka-http

Java DSL: Marshaller not usable to easily create HttpRequests

Open

#2,128 opened on Jul 26, 2018

View on GitHub
 (0 comments) (1 reaction) (0 assignees)Scala (598 forks)batch import
1 - triagedhelp wantedt:core

Repository metrics

Stars
 (1,311 stars)
PR merge metrics
 (Avg merge 1d 10h) (2 merged PRs in 30d)

Description

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