Akka-http是同码系统融为一体工具。这要因系统内的数据交换功能。因为程序外数据表达形式与网上传的数码格式是休一致之,所以需要针对程序高级结构化的多少开展转换(marshalling
or
serializing)成为可当网上传的数据格式。由于可能涉及到异类系统并,网上传输数据格式是一个当面的科班,这样大家才都得以拓展解析。Json就是凡一个时业界普遍接受之网上交换数据格式。当然,所谓的数据格式转换应该是双向的,还需要包括将吸收的网上传输数据易成为程序高级结构化数据。

Akka-http网上交换数据易代表把一个高档结构类型T的实例转换成简单的靶子项目如MessageEntity,它表示http消息中之数有(entity-body),最后来Json进行交换。Akka-http用Marshaller[A,B]种类来拓展类型A的实例到品种B实例的换。Marshaller[A,B]概念如下:

sealed abstract class Marshaller[-A, +B] {

  def apply(value: A)(implicit ec: ExecutionContext): Future[List[Marshalling[B]]]

  def map[C](f: B ⇒ C): Marshaller[A, C] =
    Marshaller(implicit ec ⇒ value ⇒ this(value).fast map (_ map (_ map f)))
...
}

//#marshaller-creation
object Marshaller
  extends GenericMarshallers
  with PredefinedToEntityMarshallers
  with PredefinedToResponseMarshallers
  with PredefinedToRequestMarshallers {

  /**
   * Creates a [[Marshaller]] from the given function.
   */
  def apply[A, B](f: ExecutionContext ⇒ A ⇒ Future[List[Marshalling[B]]]): Marshaller[A, B] =
    new Marshaller[A, B] {
      def apply(value: A)(implicit ec: ExecutionContext) =
        try f(ec)(value)
        catch { case NonFatal(e) ⇒ FastFuture.failed(e) }
    }
...
}

构建函数apply[A,B]包嵌了单操作函数:A=>Future[List[Marshalling[B]]],至于缘何未采取重复简单直接的方法A=>B是为:

1、转换的历程是异步non-blocking的,所以回来Future[??]

2、可能发多种转移目标数格式如XML,Json:所以用List[??]表达

3、如果用在发最终目标格式数据前能够得或者修改数据的性能,就需以数据源与对象数中如果一个当中层结果,Marshalling[B]纵然是这样一个中级抽象层类型。通过Marshalling类型可以当多少实际上有前获得或涂改数据性:

/**
 * Describes one possible option for marshalling a given value.
 */
sealed trait Marshalling[+A] {
  def map[B](f: A ⇒ B): Marshalling[B]

  /**
   * Converts this marshalling to an opaque marshalling, i.e. a marshalling result that
   * does not take part in content type negotiation. The given charset is used if this
   * instance is a `WithOpenCharset` marshalling.
   */
  def toOpaque(charset: HttpCharset): Marshalling[A]
}

object Marshalling {

  /**
   * A Marshalling to a specific [[akka.http.scaladsl.model.ContentType]].
   */
  final case class WithFixedContentType[A](
    contentType: ContentType,
    marshal:     () ⇒ A) extends Marshalling[A] {
    def map[B](f: A ⇒ B): WithFixedContentType[B] = copy(marshal = () ⇒ f(marshal()))
    def toOpaque(charset: HttpCharset): Marshalling[A] = Opaque(marshal)
  }

  /**
   * A Marshalling to a specific [[akka.http.scaladsl.model.MediaType]] with a flexible charset.
   */
  final case class WithOpenCharset[A](
    mediaType: MediaType.WithOpenCharset,
    marshal:   HttpCharset ⇒ A) extends Marshalling[A] {
    def map[B](f: A ⇒ B): WithOpenCharset[B] = copy(marshal = cs ⇒ f(marshal(cs)))
    def toOpaque(charset: HttpCharset): Marshalling[A] = Opaque(() ⇒ marshal(charset))
  }

  /**
   * A Marshalling to an unknown MediaType and charset.
   * Circumvents content negotiation.
   */
  final case class Opaque[A](marshal: () ⇒ A) extends Marshalling[A] {
    def map[B](f: A ⇒ B): Opaque[B] = copy(marshal = () ⇒ f(marshal()))
    def toOpaque(charset: HttpCharset): Marshalling[A] = this
  }
}

咱俩可于Marshalling类型里对信息内容类型(message-content-type)进行操作。为了方便操作,Akka-http提供了下就几只类别别名:

type ToEntityMarshaller[T] = Marshaller[T, MessageEntity]
type ToByteStringMarshaller[T] = Marshaller[T, ByteString]
type ToHeadersAndEntityMarshaller[T] = Marshaller[T, (immutable.Seq[HttpHeader], MessageEntity)]
type ToResponseMarshaller[T] = Marshaller[T, HttpResponse]
type ToRequestMarshaller[T] = Marshaller[T, HttpRequest]

差不多是因目标数据类型来分类代表的。Akka-http提供了众多档的预设实例到Mashalling转换:

PredefinedToEntityMarshallers
Array[Byte]
ByteString
Array[Char]
String
akka.http.scaladsl.model.FormData
akka.http.scaladsl.model.MessageEntity
T <: akka.http.scaladsl.model.Multipart
PredefinedToResponseMarshallers
T, if a ToEntityMarshaller[T] is available
HttpResponse
StatusCode
(StatusCode, T), if a ToEntityMarshaller[T] is available
(Int, T), if a ToEntityMarshaller[T] is available
(StatusCode, immutable.Seq[HttpHeader], T), if a ToEntityMarshaller[T] is available
(Int, immutable.Seq[HttpHeader], T), if a ToEntityMarshaller[T] is available
PredefinedToRequestMarshallers
HttpRequest
Uri
(HttpMethod, Uri, T), if a ToEntityMarshaller[T] is available
(HttpMethod, Uri, immutable.Seq[HttpHeader], T), if a ToEntityMarshaller[T] is available
GenericMarshallers
Marshaller[Throwable, T]
Marshaller[Option[A], B], if a Marshaller[A, B] and an EmptyValue[B] is available
Marshaller[Either[A1, A2], B], if a Marshaller[A1, B] and a Marshaller[A2, B] is available
Marshaller[Future[A], B], if a Marshaller[A, B] is available
Marshaller[Try[A], B], if a Marshaller[A, B] is available

Akka-http还提供了一个家伙类Marshal:

class Marshal[A](val value: A) {
  /**
   * Marshals `value` using the first available [[Marshalling]] for `A` and `B` provided by the given [[Marshaller]].
   * If the marshalling is flexible with regard to the used charset `UTF-8` is chosen.
   */
  def to[B](implicit m: Marshaller[A, B], ec: ExecutionContext): Future[B] =
    m(value).fast.map {
      _.head match {
        case Marshalling.WithFixedContentType(_, marshal) ⇒ marshal()
        case Marshalling.WithOpenCharset(_, marshal)      ⇒ marshal(HttpCharsets.`UTF-8`)
        case Marshalling.Opaque(marshal)                  ⇒ marshal()
      }
    }

  /**
   * Marshals `value` to an `HttpResponse` for the given `HttpRequest` with full content-negotiation.
   */
  def toResponseFor(request: HttpRequest)(implicit m: ToResponseMarshaller[A], ec: ExecutionContext): Future[HttpResponse] = {
    import akka.http.scaladsl.marshalling.Marshal._
    val ctn = ContentNegotiator(request.headers)

    m(value).fast.map { marshallings ⇒
      val supportedAlternatives: List[ContentNegotiator.Alternative] =
        marshallings.collect {
          case Marshalling.WithFixedContentType(ct, _) ⇒ ContentNegotiator.Alternative(ct)
          case Marshalling.WithOpenCharset(mt, _)      ⇒ ContentNegotiator.Alternative(mt)
        }(collection.breakOut)
      val bestMarshal = {
        if (supportedAlternatives.nonEmpty) {
          ctn.pickContentType(supportedAlternatives).flatMap {
            case best @ (_: ContentType.Binary | _: ContentType.WithFixedCharset | _: ContentType.WithMissingCharset) ⇒
              marshallings collectFirst { case Marshalling.WithFixedContentType(`best`, marshal) ⇒ marshal }
            case best @ ContentType.WithCharset(bestMT, bestCS) ⇒
              marshallings collectFirst {
                case Marshalling.WithFixedContentType(`best`, marshal) ⇒ marshal
                case Marshalling.WithOpenCharset(`bestMT`, marshal)    ⇒ () ⇒ marshal(bestCS)
              }
          }
        } else None
      } orElse {
        marshallings collectFirst { case Marshalling.Opaque(marshal) ⇒ marshal }
      } getOrElse {
        throw UnacceptableResponseContentTypeException(supportedAlternatives.toSet)
      }
      bestMarshal()
    }
  }
}

咱得以据此Marshal.to和toResponseFor(request)把Akka-http提供的预设可转换类实例转换成相关的toResponseMarshallable类实例。因为Server-Directive如complete接受一个toResponseMarshallable来构建HttpResponse:

  /**
   * Completes the request using the given arguments.
   *
   * @group route
   */
  def complete(m: ⇒ ToResponseMarshallable): StandardRoute =
    StandardRoute(_.complete(m))

于旁一个对象里供了ToResponseMarshallable隐式转换:

/** Something that can later be marshalled into a response */
trait ToResponseMarshallable {
  type T
  def value: T
  implicit def marshaller: ToResponseMarshaller[T]

  def apply(request: HttpRequest)(implicit ec: ExecutionContext): Future[HttpResponse] =
    Marshal(value).toResponseFor(request)
}

object ToResponseMarshallable {
  implicit def apply[A](_value: A)(implicit _marshaller: ToResponseMarshaller[A]): ToResponseMarshallable =
    new ToResponseMarshallable {
      type T = A
      def value: T = _value
      def marshaller: ToResponseMarshaller[T] = _marshaller
    }

  implicit val marshaller: ToResponseMarshaller[ToResponseMarshallable] =
    Marshaller { implicit ec ⇒ marshallable ⇒ marshallable.marshaller(marshallable.value) }
}

若是在可视域内(implicit
scope)能觉察Marshaller[A,B]的隐式实例就可知满足complete入参要求了。下面是局部Marshal用例:

import akka.util.ByteString
import akka.http.scaladsl.model.{HttpResponse, MessageEntity}
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._

object Marshalling  {

  val string = "Yeah"
  val entityFuture = Marshal(string).to[MessageEntity]
  val errorMsg = "Easy, pal!"
  val responseFuture = Marshal(420 -> errorMsg).to[HttpResponse]
  val request = HttpRequest(headers = List(headers.Accept(MediaTypes.`application/json`)))
  val responseText = "Plaintext"
  val respFuture = Marshal(responseText).toResponseFor(request) // with content negotiation!
  val bsFuture = Marshal("oh my!").to[ByteString]
  val reqFuture = Marshal("can you?").to[HttpRequest]
  val resp = reqFuture.flatMap {r => Marshal("ok").toResponseFor(r)}

}

那对于那些由定义的类型U,由于未可能来先设定对应的Marshaller[U,B],应该怎么收拾?如简单的case
class:

  case class User(id: Int, name: String)
  case class Item(id: Int, name: String, price: Double)
  val john = Marshal(User(1,"John")).to[MessageEntity]
  val fruit = Marshal(Item(1,"banana", 3.5)).to[MessageEntity]

  val route =
    get {
      path("items") {
        complete(fruit)
      } ~
      path("users") {
        complete(john)
      }
    }

看来将User,Item类型实例转成为ToResponseMarshallable是没有问题之。但是,通过隐式转换ToResponseMarshallable被移成为Marshaller[U,B],而实例化这个项目的进程即构建网上传输格式的数码常常欲还多的支撑。这个可网上传输的音信是通过Json、XML这样的数据描述语言来产生实际数额的。Akka-http通过akka-http-spray-json模块直接支持由Spray-Json实现的Json读写工具库。具体Json读写是通过RootJsonFormat[T]作为接口实现的:

/**
 * A special JsonFormat signaling that the format produces a legal JSON root object, i.e. either a JSON array
 * or a JSON object.
 */
trait RootJsonFormat[T] extends JsonFormat[T] with RootJsonReader[T] with RootJsonWriter[T]

RootJsonFormat[T]代表T类型实例的Json转换。RootJsonFormat[T]的继承父辈包括:
/**
  * Provides the JSON deserialization and serialization for type T.
 */
trait JsonFormat[T] extends JsonReader[T] with JsonWriter[T]

/**
 * A special JsonReader capable of reading a legal JSON root object, i.e. either a JSON array or a JSON object.
 */
@implicitNotFound(msg = "Cannot find RootJsonReader or RootJsonFormat type class for ${T}")
trait RootJsonReader[T] extends JsonReader[T]

/**
 * A special JsonWriter capable of writing a legal JSON root object, i.e. either a JSON array or a JSON object.
 */
@implicitNotFound(msg = "Cannot find RootJsonWriter or RootJsonFormat type class for ${T}")
trait RootJsonWriter[T] extends JsonWriter[T]

她又累了具体的Json读写工具类:

/**
  * Provides the JSON deserialization for type T.
 */
@implicitNotFound(msg = "Cannot find JsonReader or JsonFormat type class for ${T}")
trait JsonReader[T] {
  def read(json: JsValue): T
}

object JsonReader {
  implicit def func2Reader[T](f: JsValue => T): JsonReader[T] = new JsonReader[T] {
    def read(json: JsValue) = f(json)
  }
}

/**
  * Provides the JSON serialization for type T.
 */
@implicitNotFound(msg = "Cannot find JsonWriter or JsonFormat type class for ${T}")
trait JsonWriter[T] {
  def write(obj: T): JsValue
}

object JsonWriter {
  implicit def func2Writer[T](f: T => JsValue): JsonWriter[T] = new JsonWriter[T] {
    def write(obj: T) = f(obj)
  }
}

它们提供了函数JsValue=>T到JsonReader[T]暨T=>JsValue到JsonWriter直接的隐式转换。Akka-http的Json解决方案是百里挑一的type-class模式:是同栽好无限制创建效能的品类继承模式(add-hoc
polymorphism)。它的特色就是是当可视域内(implicit
scope)应不同作用要求提供不同的职能实现项目的隐式实例(implicit
instance)。具体用例如下:

trait Formats extends SprayJsonSupport with DefaultJsonProtocol
object Converters extends Formats {
  case class User(id: Int, name: String)
  case class Item(id: Int, name: String, price: Double)
  implicit val itemFormat = jsonFormat3(Item.apply)
  implicit val userFormat = jsonFormat2(User.apply)
}

jsonFormatXX是Spray-Json提供的Json读写实现。我们将这个隐式实例置于当前可视域内便成功了跟Akka-http的连片。我们来探望JsonFormat的定义:

trait ProductFormatsInstances { self: ProductFormats with StandardFormats =>
  // Case classes with 1 parameters

  def jsonFormat1[P1 :JF, T <: Product :ClassManifest](construct: (P1) => T): RootJsonFormat[T] = {
    val Array(p1) = extractFieldNames(classManifest[T])
    jsonFormat(construct, p1)
  }
  def jsonFormat[P1 :JF, T <: Product](construct: (P1) => T, fieldName1: String): RootJsonFormat[T] = new RootJsonFormat[T]{
    def write(p: T) = {
      val fields = new collection.mutable.ListBuffer[(String, JsValue)]
      fields.sizeHint(1 * 2)
      fields ++= productElement2Field[P1](fieldName1, p, 0)
      JsObject(fields: _*)
    }
    def read(value: JsValue) = {
      val p1V = fromField[P1](value, fieldName1)
      construct(p1V)
    }
  }
...
}

咱看到了jsonFormat返回结果类型是RootJsonFormat[T]。如果产生个case
class T,通过jsonFormat可以收获read(value:
JsValue)及write(p:T)这有限个具体的Json读写函数。Spray-Json提供的预设了Json转换的类包括下面各类别:

/**
  * Provides all the predefined JsonFormats.
 */
trait DefaultJsonProtocol
        extends BasicFormats
        with StandardFormats
        with CollectionFormats
        with ProductFormats
        with AdditionalFormats

object DefaultJsonProtocol extends DefaultJsonProtocol

例如BasicFormat:

/**
  * Provides the JsonFormats for the most important Scala types.
 */
trait BasicFormats {

  implicit object IntJsonFormat extends JsonFormat[Int] {
    def write(x: Int) = JsNumber(x)
    def read(value: JsValue) = value match {
      case JsNumber(x) => x.intValue
      case x => deserializationError("Expected Int as JsNumber, but got " + x)
    }
  }
...
}

这些类别的Json转换已经是切实可行的read/write操作了。在SprayJsonSupport
trait里发出最后的Marshaller[U,B]链接:

/**
 * A trait providing automatic to and from JSON marshalling/unmarshalling using an in-scope *spray-json* protocol.
 */
trait SprayJsonSupport {
...
  implicit def sprayJsonUnmarshaller[T](implicit reader: RootJsonReader[T]): FromEntityUnmarshaller[T] =
    sprayJsValueUnmarshaller.map(jsonReader[T].read)
...
  //#sprayJsonMarshallerConverter
  implicit def sprayJsonMarshaller[T](implicit writer: RootJsonWriter[T], printer: JsonPrinter = CompactPrinter): ToEntityMarshaller[T] =
    sprayJsValueMarshaller compose writer.write
...
}

我们以方提到过FromEntityUnmarshaller[T]和ToEntityMarshaller[T]的是Marshaller[A,B]的别名:

  type FromEntityUnmarshaller[T] = Unmarshaller[HttpEntity, T]

  type ToEntityMarshaller[T] = Marshaller[T, MessageEntity]

既然Akka-http的Json实现方式是type-class模式之,那么我们虽尝试其它Json库的法力实现方式,如:Json4s。我们用在build.sbt中入下面的赖:

  "de.heikoseeberger" %% "akka-http-json4s" % "1.19.0-M2",
  "org.json4s" %% "json4s-jackson" % "3.6.0-M1",
  "org.json4s" %% "json4s-ext" % "3.6.0-M1",

 akka-http-Json4s通过trait
Json4sSupport提供了Json4s实现方式:

trait Json4sSupport {
...
  /**
    * HTTP entity => `A`
    *
    * @tparam A type to decode
    * @return unmarshaller for `A`
    */
  implicit def unmarshaller[A: Manifest](implicit serialization: Serialization,
                                         formats: Formats): FromEntityUnmarshaller[A] = ...

  /**
    * `A` => HTTP entity
    *
    * @tparam A type to encode, must be upper bounded by `AnyRef`
    * @return marshaller for any `A` value
    */
  implicit def marshaller[A <: AnyRef](implicit serialization: Serialization,
                                       formats: Formats,
                                       shouldWritePretty: ShouldWritePretty =
                                         ShouldWritePretty.False): ToEntityMarshaller[A] = ...

平提供了FromEntityUnMarshaller[A]和ToEntityMarshaller[A]当即有限像样的隐式实例。Serialization提供了Json的具体读写函数:

trait Serialization {
  import java.io.{Reader, Writer}
  /** Serialize to String.
   */
  def write[A <: AnyRef](a: A)(implicit formats: Formats): String
...
  /** Deserialize from a String.
   */
  def read[A](json: String)(implicit formats: Formats, mf: Manifest[A]): A = read(StringInput(json))
...
}

Formats就是Json4s提供的保有Json转换预设类:

trait Formats extends Serializable { self: Formats =>
...
  def withBigInt: Formats = copy(wWantsBigInt = true)

  def withLong: Formats = copy(wWantsBigInt = false)

  def withBigDecimal: Formats = copy(wWantsBigDecimal = true)

...
}

在押起我们只是待在可视域内提供Serialization和Formats类型的隐式实例就行了:

import de.heikoseeberger.akkahttpjson4s.Json4sSupport
import org.json4s.jackson
trait JsonCodec extends Json4sSupport {
  import org.json4s.DefaultFormats
  import org.json4s.ext.JodaTimeSerializers
  implicit val serilizer = jackson.Serialization
  implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
}
object JsConverters extends JsonCodec

探访实际用例:

  import scala.collection.mutable._
  case class User(id: Int, name: String)
  class Item(id: Int, name: String, price: Double)
  object AnyPic {
    val area = 10
    val title = "a picture"
    val data = ArrayBuffer[Byte](1,2,3)
  }

  val john = Marshal(User(1,"John")).to[MessageEntity]
  val fruit = Marshal(new Item(1,"banana", 3.5)).to[MessageEntity]
  val pic = Marshal(AnyPic).to[MessageEntity]

不只省却了再度的JsonFormatXX,而且作用逾灵敏有力:因为不再局限为case
class这无异栽由定义类型了,在无需额外代码情况下class,object等一切都支持。

脚是本篇讨论示范的源代码:

build.sbt

name := "learn-http"

version := "0.1"

scalaVersion := "2.12.3"

libraryDependencies ++= Seq(
  "de.heikoseeberger" %% "akka-http-json4s" % "1.19.0-M2",
  "org.json4s" %% "json4s-jackson" % "3.6.0-M1",
  "org.json4s" %% "json4s-ext" % "3.6.0-M1",
  "com.typesafe.akka" %% "akka-http" % "10.0.10",
  "com.typesafe.akka" %% "akka-actor" % "2.5.4",
  "com.typesafe.akka" %% "akka-stream" % "2.5.4",
  "com.typesafe.akka" %% "akka-http-spray-json" % "10.0.10"
)

Marshalling

import akka.actor._
import akka.stream._
import akka.util.ByteString
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.marshallers.sprayjson._
import spray.json._

trait Formats extends SprayJsonSupport with DefaultJsonProtocol
object Converters extends Formats {
  case class User(id: Int, name: String)
  case class Item(id: Int, name: String, price: Double)
  implicit val itemFormat = jsonFormat3(Item.apply)
  implicit val userFormat = jsonFormat2(User.apply)
}


object Marshalling {
  import Converters._
  implicit val httpSys = ActorSystem("httpSystem")
  implicit val httpMat = ActorMaterializer()
  implicit val httpEC = httpSys.dispatcher



  val string = "Yeah"
  val entityFuture = Marshal(string).to[MessageEntity]
  val errorMsg = "Easy, pal!"
  val responseFuture = Marshal(420 -> errorMsg).to[HttpResponse]
  val request = HttpRequest(headers = List(headers.Accept(MediaTypes.`application/json`)))
  val responseText = "Plaintext"
  val respFuture = Marshal(responseText).toResponseFor(request)

//  val bsFuture = Marshal("oh my!").to[ByteString]
  //  val reqFuture = Marshal(400).to[HttpRequest]
  //  val resp = reqFuture.flatMap {r => Marshal("ok").toResponseFor(r)}


  val john = Marshal(User(1,"John")).to[MessageEntity]
  val fruit = Marshal(Item(1,"banana", 3.5)).to[MessageEntity]

  val route =
    get {
      path("items") {
        complete(fruit)
      } ~
        path("users") {
          complete(john)
        }
    }

}

 Json4sMarshalling

import akka.actor._
import akka.stream._
import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import de.heikoseeberger.akkahttpjson4s.Json4sSupport
import org.json4s.jackson
trait JsonCodec extends Json4sSupport {
  import org.json4s.DefaultFormats
  import org.json4s.ext.JodaTimeSerializers
  implicit val serilizer = jackson.Serialization
  implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
}
object JsConverters extends JsonCodec


object Json4sMarshalling {
  import JsConverters._
  implicit val httpSys = ActorSystem("httpSystem")
  implicit val httpMat = ActorMaterializer()
  implicit val httpEC = httpSys.dispatcher

  val string = "Yeah"
  val entityFuture = Marshal(string).to[MessageEntity]
  val errorMsg = "Easy, pal!"
  val responseFuture = Marshal(420 -> errorMsg).to[HttpResponse]
  val request = HttpRequest(headers = List(headers.Accept(MediaTypes.`application/json`)))
  val responseText = "Plaintext"
  val respFuture = Marshal(responseText).toResponseFor(request)




  import scala.collection.mutable._
  case class User(id: Int, name: String)
  class Item(id: Int, name: String, price: Double)
  object AnyPic {
    val area = 10
    val title = "a picture"
    val data = ArrayBuffer[Byte](1,2,3)
  }

  val john = Marshal(User(1,"John")).to[MessageEntity]
  val fruit = Marshal(new Item(1,"banana", 3.5)).to[MessageEntity]
  val pic = Marshal(AnyPic).to[MessageEntity]

  val route =
    get {
      path("items") {
        complete(fruit)
      } ~
        path("users") {
          complete(john)
        } ~
      path("pic") {
        complete(pic)
      }
    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章

网站地图xml地图