Skip to content

Commit

Permalink
Fix 606 Webserver documentation does not describe services (#608)
Browse files Browse the repository at this point in the history
* Fix 606 Webserver documentation does not describe services
  • Loading branch information
barchetta authored Apr 22, 2019
1 parent 284a89b commit 9ecedbe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
28 changes: 28 additions & 0 deletions docs/src/main/docs/webserver/03_routing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,31 @@ requests accepted by the predicate. All other requests are _nexted_, meaning tha
})
.otherwise((req, resp) -> { /* Otherwise logic */ }); // Optional. Default logic is req.next()
----
== Organizing Code into Services
By implementing the `Service` interface you can organize your code into one
or more services, each with its own path prefix and set of handlers.
[source,java]
.Use `Routing.Builder.register` to register your service
----
.register("/hello", new HelloService())
----
[source,java]
.Service implementation
----
public class HelloService implements Service {
@Override
public void update(Routing.Rules rules) {
rules.get("/subpath", this::getHandler);
}
private void getHandler(ServerRequest request,
ServerResponse response) {
// Some logic
}
}
----
In this example, the `GET` handler matches requests to `/hello/subpath`.
22 changes: 1 addition & 21 deletions docs/src/main/docs/webserver/05_error-handling.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,23 +97,3 @@ exception called `req.next()`, then the exception is translated to an HTTP respo
error code `500`.
== Registering an application - Organizing code into services
You can also register an application that has its own handlers at a path prefix or context root.
[source,java]
.Registering routing logic for a context root
----
.register("/context-root", new MyComplexApplication())
----
[source,java]
.Routing logic implementation
----
public class MyComplexApplication implements Consumer<Routing.Config> {
@Override
public void accept(Routing.Config config) {
config.get("/subpath", (req, res) -> {/* handler */});
}
}
----
In this example, the `GET` handler matches requests to `/context-root/subpath`.

0 comments on commit 9ecedbe

Please sign in to comment.