How can I add contextRoot in Helidon SE? #7707
-
as the title says, how can I add contextRoot in Helidon SE? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Use a path when you register handlers and services. If you have a simple layout with just handlers, simply add a prefix to your paths: routing.get("/acme/foo", (req, res) -> res.send("Foo"))
.get("/acme/bar", (req, res) -> res.send("Bar"));
// /acme/foo -> "Foo"
// /acme/bar -> "Bar" You can use services to group handlers under a common path: routing.register("/acme", rules ->
rules.get("/foo", (req, res) -> res.send("Foo"))
.get("/bar", (req, res) -> res.send("Bar")));
// /acme/foo -> "Foo"
// /acme/bar -> "Bar" Services can register nested services: routing.register("/acme", rules1 ->
rules1.register("/api", rules2 ->
rules2.get("/foo", (req, res) -> res.send("Foo"))
.get("/bar", (req, res) -> res.send("Bar"))));
// /acme/api/foo -> "Foo"
// /acme/api/bar -> "Bar" Note that I wrote the services using lambdas because that's more compact for answer, but in practice it's better to use a class that implements See the documentation here: https://helidon.io/docs/v3/#/se/webserver#_routing |
Beta Was this translation helpful? Give feedback.
Use a path when you register handlers and services.
If you have a simple layout with just handlers, simply add a prefix to your paths:
You can use services to group handlers under a common path:
Services can register nested services: