You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Route and Router does no longer require a "path" argument in their constructor! This will be set by using WebserverBuilder#addRoute(String, Route), WebserverBuilder#addRouter(String, Router) or Router#addRoute(String, Route)
Removed Debug messages in Webserver#handle
Made Webserver#handle compatible with the new Route and Router
updated the version to 1.2
updated the README.md to explain the new Route and Router
Copy file name to clipboardExpand all lines: README.md
+27-21Lines changed: 27 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ You can also download the newest version from the [releases](https://github.com/
14
14
<dependency>
15
15
<groupId>de.joshicodes</groupId>
16
16
<artifactId>webapi</artifactId>
17
-
<version>1.1.2</version>
17
+
<version>1.2</version>
18
18
</dependency>
19
19
```
20
20
@@ -34,17 +34,15 @@ To add a new route, create a new class that extends the `Route` class and add it
34
34
The `Route` class has a constructor that takes a path as a parameter. The path is the path that the route will be available on.
35
35
36
36
```java
37
+
// This will create a new route that is available on /testRoute
37
38
builder.addRoute(
38
-
// You can also create a new Route object and add it here
39
-
40
-
// This will create a new route that is available on /testRoute
41
-
newRoute("/testRoute") {
39
+
"/testRoute",
40
+
newRoute() {
42
41
@Override
43
42
publicResponseDatahandle(RequestDatarequest) {
44
43
// Do something and return a ResponseData object
45
44
}
46
45
}
47
-
48
46
);
49
47
```
50
48
You can also add multiple routes at once using `builder.addRoutes(Route...)`.
@@ -54,27 +52,35 @@ To register a new Router, you can use `WebserverBuilder#addRouter(Router)`.
54
52
The `Router` class has a constructor that takes a path as a parameter. The path is the base path that the router will be available on.
55
53
56
54
```java
57
-
// This will create a new router that is available on /testRouter
58
-
Router router =newRouter("/testRouter");
55
+
// This will create a new router without any path, that will be set by registering it to the builder
56
+
// This router will be available on /testRouter
57
+
Router router =newRouter();
59
58
60
59
// This will create a new route that is available on /testRouter
61
60
// If there is no Route for "/" in the Router, "/testRouter" will return a 404
62
-
router.addRoute(newRoute("/") {
63
-
@Override
64
-
publicResponseDatahandle(RequestDatarequest) {
65
-
// Do something and return a ResponseData object
66
-
}
67
-
});
61
+
router.addRoute(
62
+
"/",
63
+
newRoute() {
64
+
@Override
65
+
publicResponseDatahandle(RequestDatarequest) {
66
+
// Do something and return a ResponseData object
67
+
}
68
+
}
69
+
);
68
70
69
71
// This will create a new route that is available on /testRouter/testRoute
70
-
router.addRoute(newRoute("/testRoute") {
71
-
@Override
72
-
publicResponseDatahandle(RequestDatarequest) {
73
-
// Do something and return a ResponseData object
74
-
}
75
-
});
72
+
router.addRoute(
73
+
"/testRoute",
74
+
newRoute() {
75
+
@Override
76
+
publicResponseDatahandle(RequestDatarequest) {
77
+
// Do something and return a ResponseData object
78
+
}
79
+
}
80
+
);
76
81
77
-
builder.addRouter(router);
82
+
// This will register the router to the builder
83
+
builder.addRouter("/testRouter", router);
78
84
```
79
85
80
86
The `Route` class has a method called `handle(RequestData request)`. This method is called when a request is made to the route. The `RequestData` object contains information about the request. The `handle` Method should return a ResponseData object.
0 commit comments