route to record class, better actions
This commit is contained in:
@@ -29,11 +29,11 @@ public class HttpServer {
|
||||
}
|
||||
|
||||
public void GET(String path, HttpHandler handler) {
|
||||
router.addRoute("GET", path, handler);
|
||||
router.addRoute(HttpMethod.GET, path, handler);
|
||||
}
|
||||
|
||||
public void POST(String path, HttpHandler handler) {
|
||||
router.addRoute("POST", path, handler);
|
||||
router.addRoute(HttpMethod.POST, path, handler);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package org.lumijiez.core.routing;
|
||||
|
||||
public class Route {
|
||||
private final HttpMethod method;
|
||||
private final String path;
|
||||
private final HttpHandler handler;
|
||||
import org.lumijiez.core.http.HttpHandler;
|
||||
import org.lumijiez.core.http.HttpMethod;
|
||||
|
||||
public Route(HttpMethod method, String path, HttpHandler handler) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
// Add getters...
|
||||
public record Route(HttpMethod method, String path, HttpHandler handler) {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.lumijiez.core.routing;
|
||||
|
||||
import org.lumijiez.core.http.HttpHandler;
|
||||
import org.lumijiez.core.http.HttpMethod;
|
||||
import org.lumijiez.core.http.HttpRequest;
|
||||
import org.lumijiez.core.http.HttpResponse;
|
||||
import org.lumijiez.core.middleware.Chain;
|
||||
@@ -49,7 +50,7 @@ public class Router {
|
||||
Route route = routes.get(key);
|
||||
|
||||
if (route != null) {
|
||||
route.getHandler().handle(request, response);
|
||||
route.handler().handle(request, response);
|
||||
} else {
|
||||
response.sendResponse(HttpStatus.NOT_FOUND, "Not Found");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user