use of io.helidon.webserver.Handler in project helidon by oracle.
the class Main method routingAsFilter.
/**
* All routing rules (routes) are evaluated in a definition order. The {@link Handler} assigned with the first valid route
* for given request is called. It is a responsibility of each handler to process in one of the following ways:
* <ul>
* <li>Respond using one of {@link io.helidon.webserver.ServerResponse#send() ServerResponse.send(...)} method.</li>
* <li>Continue to next valid route using {@link io.helidon.webserver.ServerRequest#next() ServerRequest.next()} method.
* <i>It is possible to define filtering handlers.</i></li>
* </ul>
* <p>
* If no valid {@link Handler} is found then routing respond by {@code HTTP 404} code.
* <p>
* If selected {@link Handler} doesn't process request than the request <b>stacks</b>!
* <p>
* <b>Blocking operations:</b><br>
* For performance reason, {@link Handler} can be called directly by a selector thread. It is not good idea to block
* such thread. If request must be processed by a blocking operation then such processing should be deferred to another
* thread.
*/
public void routingAsFilter() {
Routing routing = Routing.builder().any((req, res) -> {
System.out.println(req.method() + " " + req.path());
// Filters are just routing handlers which calls next()
req.next();
}).post("/post-endpoint", (req, res) -> res.status(Http.Status.CREATED_201).send()).get("/get-endpoint", (req, res) -> res.status(Http.Status.NO_CONTENT_204).send("Hello World!")).build();
startServer(routing);
}
use of io.helidon.webserver.Handler in project helidon by oracle.
the class Main method firstRouting.
// ---------------- EXAMPLES
/**
* True heart of WebServer API is {@link Routing}. It provides fluent way how to assign custom {@link Handler} to the routing
* rule. The rule consists from two main factors - <i>HTTP method</i> and <i>path pattern</i>.
* <p>
* The (route) {@link Handler} is a functional interface which process HTTP {@link io.helidon.webserver.ServerRequest request} and
* writes to the {@link io.helidon.webserver.ServerResponse response}.
*/
public void firstRouting() {
Routing routing = Routing.builder().post("/post-endpoint", (req, res) -> res.status(Http.Status.CREATED_201).send()).get("/get-endpoint", (req, res) -> res.status(Http.Status.NO_CONTENT_204).send("Hello World!")).build();
startServer(routing);
}
Aggregations