This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.java
More file actions
81 lines (56 loc) · 2.29 KB
/
Router.java
File metadata and controls
81 lines (56 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package io.jooby;
import org.jooby.funzy.Throwing;
import javax.annotation.Nonnull;
import java.util.stream.Stream;
public interface Router {
String ALL = "*";
String GET = "GET";
String POST = "POST";
String PUT = "PUT";
String DELETE = "DELETE";
String PATCH = "PATCH";
default @Nonnull Route before(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Before handler) {
return define(method.toUpperCase(), pattern, handler);
}
default @Nonnull Route before(@Nonnull String pattern, @Nonnull Route.Before handler) {
return define(ALL, pattern, handler);
}
default @Nonnull Route after(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.After handler) {
return define(method.toUpperCase(), pattern, handler);
}
default @Nonnull Route after(@Nonnull String pattern, @Nonnull Route.After handler) {
return define(ALL, pattern, handler);
}
default @Nonnull Route get(@Nonnull String pattern, @Nonnull Route.Handler handler) {
return define(GET, pattern, handler);
}
default @Nonnull Route post(@Nonnull String pattern, @Nonnull Route.Handler handler) {
return define(POST, pattern, handler);
}
default @Nonnull Route put(@Nonnull String pattern, @Nonnull Route.Handler handler) {
return define(PUT, pattern, handler);
}
default @Nonnull Route delete(@Nonnull String pattern, @Nonnull Route.Handler handler) {
return define(DELETE, pattern, handler);
}
default @Nonnull Route patch(@Nonnull String pattern, @Nonnull Route.Handler handler) {
return define(PATCH, pattern, handler);
}
default @Nonnull Route.Handler detach(@Nonnull Throwing.Consumer<Context> handler) {
return new Route.Handler() {
@Override public void handle(@Nonnull Context ctx, @Nonnull Route.Pipeline chain)
throws Throwable {
ctx.detach();
handler.accept(ctx);
}
@Override public Object handle(@Nonnull Context ctx) throws Throwable {
return ctx;
}
};
}
@Nonnull Route.Pipeline pipeline(@Nonnull String method, @Nonnull String path);
@Nonnull Stream<Route> routes();
@Nonnull Route define(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Filter handler);
@Nonnull Router err(@Nonnull Route.ErrHandler handler);
@Nonnull Route.ErrHandler err();
}