Package io.karatelabs.http
Class ServerRequestHandler
java.lang.Object
io.karatelabs.http.ServerRequestHandler
- All Implemented Interfaces:
Function<HttpRequest,HttpResponse>
Main request handler implementing routing for static files, API endpoints, and HTML templates.
Implements Function<HttpRequest, HttpResponse> for use with HttpServer.
Routing logic:
- If path starts with static prefix (e.g., /pub/) → serve static file
- If path starts with API prefix (e.g., /api/) → execute JS file
- Otherwise → render HTML template
Usage:
ServerConfig config = new ServerConfig()
.resourceRoot("classpath:web")
.sessionStore(new InMemorySessionStore())
.engineSupplier(Engine::new);
ServerRequestHandler handler = new ServerRequestHandler(config, resolver);
HttpServer server = HttpServer.start(8080, handler);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException used internally to signal a redirect. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ServerRequestHandler
-
-
Method Details
-
apply
- Specified by:
applyin interfaceFunction<HttpRequest,HttpResponse>
-
getConfig
-