原文链接
the usual library is spray-json
需要引入如下的lib
1 2 3 4 5 6 7 8
| import akka.http.scaladsl.server.Directives._ import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import io.circe.generic.auto._ def route = path("todos") { get { complete(todoRepository.all()) } }
|
这部分主要是用来unmarshal Json
1 2 3 4 5 6 7 8 9
| def route = path("todos") { get { complete(todoRepository.all()) } ~ post { entity(as[Todo]) { todo => complete(todoRepository.save(todo)) } } }
|
使用entity,可以自动parse输入的json到我们的model