Skip to content

Commit

Permalink
Consolidate routing-dsl index
Browse files Browse the repository at this point in the history
Needs a paradox update to remove scala-specific elements from
the indexes
  • Loading branch information
raboof committed Dec 6, 2017
1 parent fd2302d commit 23abfff
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 99 deletions.
91 changes: 0 additions & 91 deletions docs/src/main/paradox/java/http/routing-dsl/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/src/main/paradox/java/http/routing-dsl/index.md
@@ -1,3 +1,10 @@
@@@ div { .group-java }

This section is only relevant when using the Scala API

@@@

@@@ div { .group-scala }
# Case Class Extraction

The value extraction performed by @ref[Directives](directives/index.md) is a nice way of providing your route logic with interesting request
Expand Down Expand Up @@ -58,3 +65,5 @@ If you write your validations like this Akka HTTP's case class extraction logic
messages and generate a `ValidationRejection` if something goes wrong. By default, `ValidationRejections` are
converted into `400 Bad Request` error response by the default @ref[RejectionHandler](rejections.md#the-rejectionhandler), if no
subsequent route successfully handles the request.

@@@
38 changes: 30 additions & 8 deletions docs/src/main/paradox/scala/http/routing-dsl/index.md
Expand Up @@ -32,7 +32,11 @@ from a background with non-"streaming first" HTTP Servers.

This is a complete, very basic Akka HTTP application relying on the Routing DSL:

@@snip [HttpServerExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpServerExampleSpec.scala) { #minimal-routing-example }
Scala
: @@snip [HttpServerExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpServerExampleSpec.scala) { #minimal-routing-example }

Java
: @@snip [HttpServerMinimalExampleTest.java]($test$/java/docs/http/javadsl/HttpServerMinimalExampleTest.java) { #minimal-routing-example }

It starts an HTTP Server on localhost and replies to GET requests to `/hello` with a simple response.

Expand All @@ -45,11 +49,16 @@ in the Akka documentation.
To help start a server Akka HTTP provides an experimental helper class called `HttpApp`.
This is the same example as before rewritten using `HttpApp`:

@@snip [HttpAppExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpAppExampleSpec.scala) { #minimal-routing-example }
Scala
: @@snip [HttpAppExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpAppExampleSpec.scala) { #minimal-routing-example }

Java
: @@snip [HttpAppExampleTest.java]($test$/java/docs/http/javadsl/server/HttpAppExampleTest.java) { #minimal-routing-example }

See @ref[HttpApp Bootstrap](HttpApp.md) for more details about setting up a server using this approach.

<a id="long-example"></a>
@@@ div { .group-scala }

## Longer Example

The following is an Akka HTTP route definition that tries to show off a few features. The resulting service does
Expand All @@ -58,7 +67,8 @@ the Routing DSL will look like:

@@snip [HttpServerExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpServerExampleSpec.scala) { #long-routing-example }

<a id="handling-http-server-failures-high-level-scala"></a>
@@@

## Handling HTTP Server failures in the High-Level API

There are various situations when failure may occur while initialising or running an Akka HTTP server.
Expand All @@ -70,9 +80,13 @@ end-point explicitly.

For example the server might be unable to bind to the given port. For example when the port
is already taken by another application, or if the port is privileged (i.e. only usable by `root`).
In this case the "binding future" will fail immediately, and we can react to it by listening on the Future's completion:
In this case the "binding future" will fail immediately, and we can react to it by listening on the @scala[`Future`]@java[`CompletionStage`]'s completion:

Scala
: @@snip [HttpServerExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpServerExampleSpec.scala) { #binding-failure-high-level-example }

@@snip [HttpServerExampleSpec.scala]($test$/scala/docs/http/scaladsl/HttpServerExampleSpec.scala) { #binding-failure-high-level-example }
Java
: @@snip [HighLevelServerBindFailureExample.java]($test$/java/docs/http/javadsl/server/HighLevelServerBindFailureExample.java) { #binding-failure-high-level-example }

@@@ note
For a more low-level overview of the kinds of failures that can happen and also more fine-grained control over them
Expand All @@ -97,13 +111,21 @@ those streams both for the file and for the form fields.
Here is a simple example which just dumps the uploaded file into a temporary file on disk, collects
some form fields and saves an entry to a fictive database:

@@snip [FileUploadExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/FileUploadExamplesSpec.scala) { #simple-upload }
Scala
: @@snip [FileUploadExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/FileUploadExamplesSpec.scala) { #simple-upload }

Java
: @@snip [FileUploadExamplesTest.java]($test$/java/docs/http/javadsl/server/FileUploadExamplesTest.java) { #simple-upload }

You can transform the uploaded files as they arrive rather than storing them in a temporary file as
in the previous example. In this example we accept any number of `.csv` files, parse those into lines
and split each line before we send it to an actor for further processing:

@@snip [FileUploadExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/FileUploadExamplesSpec.scala) { #stream-csv-upload }
Scala
: @@snip [FileUploadExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/FileUploadExamplesSpec.scala) { #stream-csv-upload }

Java
: @@snip [FileUploadExamplesTest.java]($test$/java/docs/http/javadsl/server/FileUploadExamplesTest.java) { #stream-csv-upload }

## Configuring Server-side HTTPS

Expand Down
9 changes: 9 additions & 0 deletions docs/src/main/paradox/scala/http/routing-dsl/path-matchers.md
@@ -1,3 +1,10 @@
@@@ div { .group-java }

This DSL is only relevant when using the Scala API.

@@@

@@@ div { .group-scala }
# The PathMatcher DSL

For being able to work with the @ref[PathDirectives](directives/path-directives/index.md) effectively you should have some understanding of the
Expand Down Expand Up @@ -182,3 +189,5 @@ how to use them.
## Examples

@@snip [PathDirectivesExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/directives/PathDirectivesExamplesSpec.scala) { #path-dsl }

@@@
3 changes: 3 additions & 0 deletions project/plugins.sbt
Expand Up @@ -19,6 +19,9 @@ addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.0") // for advan
addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.1")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.4")
// From https://github.com/lightbend/paradox/pull/170
// remember to 'sbt ^publishLocal':
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.3.2-SNAPSHOT")
addSbtPlugin("com.lightbend.akka" % "sbt-paradox-akka" % "0.4")
addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.6")

Expand Down

0 comments on commit 23abfff

Please sign in to comment.