forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndertowRouting.java
More file actions
24 lines (18 loc) · 809 Bytes
/
UndertowRouting.java
File metadata and controls
24 lines (18 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.zetcode;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.RoutingHandler;
public class UndertowRouting {
public static void main(String[] args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost", ROUTES)
.build();
server.start();
}
private static HttpHandler ROUTES = new RoutingHandler()
.get("/", RoutingHandlers.plainTextHandler("GET - My Homepage"))
.get("/about", RoutingHandlers.plainTextHandler("GET - about"))
.post("/about", RoutingHandlers.plainTextHandler("POST - about"))
.get("/new*", RoutingHandlers.plainTextHandler("GET - new*"))
.setFallbackHandler(RoutingHandlers::notFoundHandler);
}