+doc #20699 improve docs for akka-http (#20722)

Made imports in docs snippets more complete and a few minor improvements
This commit is contained in:
Michal Sitko 2016-06-07 00:17:23 +02:00 committed by Konrad Malawski
parent 87a9196088
commit bf76d6c389
15 changed files with 197 additions and 161 deletions

View file

@ -8,8 +8,6 @@ import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.server.Directives
import org.scalatest.{ Matchers, WordSpec }
import scala.concurrent.Future
class SprayJsonExampleSpec extends WordSpec with Matchers {
def compileOnlySpec(body: => Unit) = ()
@ -53,6 +51,7 @@ class SprayJsonExampleSpec extends WordSpec with Matchers {
"second-spray-json-example" in compileOnlySpec {
//#second-spray-json-example
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import akka.Done
import akka.http.scaladsl.server.Route
@ -61,6 +60,10 @@ class SprayJsonExampleSpec extends WordSpec with Matchers {
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import spray.json.DefaultJsonProtocol._
import scala.io.StdIn
import scala.concurrent.Future
object WebServer {
// domain model
@ -80,6 +83,8 @@ class SprayJsonExampleSpec extends WordSpec with Matchers {
// needed to run the route
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
// needed for the future map/flatmap in the end
implicit val executionContext = system.dispatcher
val route: Route =
get {
@ -104,6 +109,13 @@ class SprayJsonExampleSpec extends WordSpec with Matchers {
}
}
val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ system.terminate()) // and shutdown when done
}
}
//#second-spray-json-example