Skip to content

Commit

Permalink
Add HTTP custom method example to doc (akka#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardimaoka committed Mar 29, 2017
1 parent 877f77f commit a278c99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/src/main/paradox/java/http/common/http-model.md
Expand Up @@ -346,6 +346,14 @@ Similarily to the media types registration, you can register custom status codes

@@snip [CustomStatusCodesExampleTest.java](../../../../../test/java/docs/http/javadsl/CustomStatusCodesExampleTest.java) { #application-custom-java }

<a id="registeringcustommethod"></a>
## Registering Custom HTTP Method

Akka HTTP also allows you to define custome HTTP methods, other than the well-known methods @javadoc[predefined](akka.http.javadsl.model.HttpMethods) in Akka HTTP.
To use a custom HTTP method, you need to define it, and then add it to parser settings like below:

@@snip [CustomHttpMethodsExampleTest.java](../../../../../test/java/docs/http/javadsl/server/directives/CustomHttpMethodExamplesTest.java) { #customHttpMethod }

## The URI model

Akka HTTP offers its own specialised URI model class which is tuned for both performance and idiomatic usage within
Expand Down
8 changes: 8 additions & 0 deletions docs/src/main/paradox/scala/http/common/http-model.md
Expand Up @@ -359,6 +359,14 @@ Similarily to the media types registration, you can register custom status codes

@@snip [CustomStatusCodesSpec.scala](../../../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/CustomStatusCodesSpec.scala) { #application-custom }

<a id="registeringcustommethod"></a>
## Registering Custom HTTP Method

Akka HTTP also allows you to define custome HTTP methods, other than the well-known methods @scaladoc[predefined](akka.http.scaladsl.model.HttpMethods$) in Akka HTTP.
To use a custom HTTP method, you need to define it, and then add it to parser settings like below:

@@snip [CustomHttpMethodSpec.scala](../../../../../test/scala/docs/http/scaladsl/server/directives/CustomHttpMethodSpec.scala) { #application-custom }

## The URI model

Akka HTTP offers its own specialised URI model class which is tuned for both performance and idiomatic usage within
Expand Down
Expand Up @@ -38,8 +38,12 @@ public void testComposition() throws InterruptedException, ExecutionException {
String host = "127.0.0.1";

//#customHttpMethod

// define custom method type:
HttpMethod BOLT =
HttpMethods.createCustom("BOLT", false, true, Expected);

// add custom method to parser settings:
final ParserSettings parserSettings =
ParserSettings.create(system).withCustomMethods(BOLT);
final ServerSettings serverSettings =
Expand Down
Expand Up @@ -30,7 +30,7 @@ class CustomHttpMethodSpec extends AkkaSpec with ScalaFutures
//#application-custom
import akka.http.scaladsl.settings.{ ParserSettings, ServerSettings }

// define custom media type:
// define custom method type:
val BOLT = HttpMethod.custom("BOLT", safe = false,
idempotent = true, requestEntityAcceptance = Expected)

Expand Down

0 comments on commit a278c99

Please sign in to comment.